|
| 1 | +# ClaudeMCPTools.jl |
| 2 | + |
| 3 | +A Julia implementation of basic Model Context Protocol (MCP) tools for Claude and other AI assistants. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **MCP Server**: Full implementation of the Model Context Protocol server |
| 8 | +- **Bash Tool**: Execute shell commands with proper stdout/stderr/exit code handling |
| 9 | +- **String Replace Editor Tool**: Edit files using string replacement operations |
| 10 | +- **Extensible Architecture**: Easy to add new tools by implementing the `MCPTool` interface |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```julia |
| 15 | +using Pkg |
| 16 | +Pkg.add(url="https://github.com/JuliaComputing/ClaudeMCPTools.jl") |
| 17 | +``` |
| 18 | + |
| 19 | +## Quick Start |
| 20 | + |
| 21 | +```julia |
| 22 | +using ClaudeMCPTools |
| 23 | + |
| 24 | +# Create an MCP server |
| 25 | +server = MCPServer(name="MyServer", version="1.0.0") |
| 26 | + |
| 27 | +# Register tools |
| 28 | +register_tool!(server, "bash", BashTool()) |
| 29 | +register_tool!(server, "editor", StrReplaceEditorTool()) |
| 30 | + |
| 31 | +# Run the server in stdio mode (for MCP communication) |
| 32 | +run_stdio_server(server) |
| 33 | +``` |
| 34 | + |
| 35 | +## Creating Custom Tools |
| 36 | + |
| 37 | +To create a custom tool, implement the `MCPTool` interface: |
| 38 | + |
| 39 | +```julia |
| 40 | +struct MyTool <: MCPTool |
| 41 | + # tool fields |
| 42 | +end |
| 43 | + |
| 44 | +function tool_schema(tool::MyTool) |
| 45 | + return Dict( |
| 46 | + "name" => "my_tool", |
| 47 | + "description" => "Description of my tool", |
| 48 | + "inputSchema" => Dict( |
| 49 | + "type" => "object", |
| 50 | + "properties" => Dict( |
| 51 | + # Define parameters |
| 52 | + ), |
| 53 | + "required" => [ |
| 54 | + # List required parameters |
| 55 | + ] |
| 56 | + ) |
| 57 | + ) |
| 58 | +end |
| 59 | + |
| 60 | +function execute(tool::MyTool, params::Dict) |
| 61 | + # Implement tool logic |
| 62 | + # Return Dict("content" => [Dict("type" => "text", "text" => result)]) |
| 63 | +end |
| 64 | +``` |
| 65 | + |
| 66 | +## Tools |
| 67 | + |
| 68 | +### BashTool |
| 69 | + |
| 70 | +Execute shell commands with full output capture: |
| 71 | + |
| 72 | +```julia |
| 73 | +bash = BashTool(working_dir="/path/to/dir", env=Dict("VAR" => "value")) |
| 74 | +result = execute(bash, Dict("command" => "echo 'Hello World'")) |
| 75 | +``` |
| 76 | + |
| 77 | +### StrReplaceEditorTool |
| 78 | + |
| 79 | +Edit files using string replacement: |
| 80 | + |
| 81 | +```julia |
| 82 | +editor = StrReplaceEditorTool(base_path="/path/to/project") |
| 83 | + |
| 84 | +# View a file |
| 85 | +execute(editor, Dict("command" => "view", "path" => "file.txt")) |
| 86 | + |
| 87 | +# Replace text |
| 88 | +execute(editor, Dict( |
| 89 | + "command" => "str_replace", |
| 90 | + "path" => "file.txt", |
| 91 | + "old_str" => "old text", |
| 92 | + "new_str" => "new text" |
| 93 | +)) |
| 94 | + |
| 95 | +# Create a new file |
| 96 | +execute(editor, Dict( |
| 97 | + "command" => "create", |
| 98 | + "path" => "new_file.txt", |
| 99 | + "file_text" => "content" |
| 100 | +)) |
| 101 | +``` |
| 102 | + |
| 103 | +## Protocol |
| 104 | + |
| 105 | +ClaudeMCPTools.jl implements the Model Context Protocol version 2024-11-05, supporting: |
| 106 | + |
| 107 | +- `initialize`: Initialize the server connection |
| 108 | +- `tools/list`: List available tools |
| 109 | +- `tools/call`: Execute a tool with parameters |
| 110 | + |
| 111 | +## Testing |
| 112 | + |
| 113 | +```julia |
| 114 | +using Pkg |
| 115 | +Pkg.test("ClaudeMCPTools") |
| 116 | +``` |
| 117 | + |
| 118 | +## License |
| 119 | + |
| 120 | +MIT License |
0 commit comments