Add MCP Tool
Agent Buildingadd-mcp-toolAdd MCP Tool is an Agent Skill for agent building published in the ricardoquesada/regenerator2000 repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Streamlines the process of adding new tools to the MCP server.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/ricardoquesada/regenerator2000/blob/HEAD/.agent/skills/add-mcp-tool/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/add-mcp-tool, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Add MCP Tool Workflow
Use this workflow when adding a new tool to the crates/regenerator2000-core/src/mcp/handler.rs server.
1. Plan the Tool
Before writing code, confirm with the user:
- Tool Name (e.g.,
r2000_get_memory) - Arguments (e.g.,
address: u16,length: u16) - Return Type (e.g.,
Vec<u8>) - Description
2. Define the Tool in list_tools
In crates/regenerator2000-core/src/mcp/handler.rs:
- Use
define_tool!macro or manually add the JSON definition inside thelist_toolsfunction. - Ensure arguments follow the JSON schema format.
Example:
json!({
"name": "r2000_my_tool",
"description": "Description of what the tool does.",
"inputSchema": {
"type": "object",
"properties": {
"arg1": { "type": "string", "description": "..." }
},
"required": ["arg1"]
}
})
3. Implement the Handler Logic
In crates/regenerator2000-core/src/mcp/handler.rs:
- Locate
handle_tool_call_internal. - Add a new match arm for your tool name.
- Call a dedicated implementation function (create one if it doesn't exist).
Example:
"r2000_my_tool" => {
let arg1 = args["arg1"].as_str().ok_or(McpError::InvalidParams("Missing arg1".to_string()))?;
let result = my_tool_impl(app_state, arg1)?;
Ok(json!({ "content": [{ "type": "text", "text": result }] }))
}
4. Create the Implementation Function
In crates/regenerator2000-core/src/mcp/handler.rs (or a sub-module):
- Create a function named
[tool_name]_impl. - Accept
&mut AppState(or&AppStateif read-only). - Return
Result<Value, McpError>or a specific type.
5. Add Verification Test
In tests/verify_mcp.py:
- Create a new function
test_[tool_name](client). - Use
client.rpc("tools/call", { ... }). - Verify the result ("PASS" or "FAIL").
- Add the function call to the
if __name__ == "__main__":block.
6. Verify Correctness
- Run the
verify-mcpskill:.agent/skills/verify-mcp/scripts/verify.sh - Fix any compilation errors or test failures.
7. Update Documentation (Optional but Recommended)
- If
docs/mcp.mdexists, update the "Tools" section with the new tool definition.