Writing a New MCP Tool

The MCP tool surface is the agent-facing API. Every tool added here is callable by any agent that has access to the relevant endpoint, so the bar for landing one is "is this useful enough to justify a slot in the decision tree on FindingTheRightMcpTool?".

When to use this runbook

When you have a concrete new agent operation in mind. Don't write speculative tools — the cost of a never-called tool is a slot wasted in the agent's decision space.

Context

A tool implements com.wikantik.mcp.tools.McpTool:

public interface McpTool {
    String name();
    McpSchema.Tool definition();
    McpSchema.CallToolResult execute( Map< String, Object > arguments );
}

Read tools live in wikantik-knowledge/src/main/java/com/wikantik/knowledge/mcp/ alongside GetPageByIdTool, SearchKnowledgeTool, and the others. Write tools live in wikantik-admin-mcp/src/main/java/com/wikantik/mcp/tools/ alongside MarkPageVerifiedTool and WritePagesTool.

Registration happens in the matching initializer:

Walkthrough

The frontmatter steps are the canonical sequence. A few elaborations:

Pitfalls

The frontmatter pitfalls capture the failure modes. The most common in practice is the registration omission — the tool compiles, the test passes, but the initializer never adds it. Cross-check by running the relevant McpToolRegistryTest (or the equivalent for knowledge-mcp).