Kest

Search

Search the documentation

MCP

Testing

Test tools, resources and prompts without HTTP.

McpTestClient calls the server in-process and shows what an AI client would see, so you can test your tools like normal code:

val module = Testing.createModule<AppModule> { import(McpModule.forRoot { name = "inventory" }) }
val mcp = McpTestClient(module.get<McpServer>())
 
assertTrue(mcp.tools().map { it["name"] }.contains("find_product"))
assertEquals("7", mcp.call("find_product", mapOf("sku" to "A1")).text)
assertTrue(mcp.call("explode").isError)                                   // a tool that throws reports an error to the model
assertTrue("B2" in mcp.read("inventory://low-stock"))
assertEquals("user" to "Plan a restock for tools.", mcp.prompt("restock_plan", mapOf("category" to "tools")).single())
assertFailsWith<McpServer.McpError> { mcp.call("no_such_tool") }          // a protocol error carries its JSON-RPC code
MethodReturns
initialize()the server's name, version and capabilities
tools(), resources(), prompts()what is offered (so you can check descriptions and schemas)
call(tool, arguments)McpToolResult(text, isError)
read(uri)the resource's text
prompt(name, arguments)the messages as role/text pairs
request(method, params)any JSON-RPC method; the result

What to test

  • Schema: a required argument is required; an optional (nullable) one can be omitted.
  • Errors: a failing tool gives isError = true with a message a model can act on.
  • Permissions: a tool refuses what the caller may not do.
  • Descriptions: the list contains the tools you expect (a renamed method silently changes the tool's name).

To test the HTTP layer too (the bearer token, origin checks), post JSON-RPC to the mounted endpoint with TestServer.

Read more