$npx -y skills add AlexAI-MCP/hermes-CCC --skill mcporterConvert any CLI tool or Python function into an MCP server using fastmcp. Zero-config tool injection into Claude Code.
| 1 | # MCPorter — CLI to MCP Converter |
| 2 | |
| 3 | Turn any Python function or CLI tool into an MCP server that Claude Code can call natively. |
| 4 | |
| 5 | ## Setup |
| 6 | |
| 7 | ```bash |
| 8 | pip install fastmcp |
| 9 | ``` |
| 10 | |
| 11 | --- |
| 12 | |
| 13 | ## Minimal Server |
| 14 | |
| 15 | ```python |
| 16 | # my_server.py |
| 17 | from fastmcp import FastMCP |
| 18 | |
| 19 | mcp = FastMCP("my-tool") |
| 20 | |
| 21 | @mcp.tool() |
| 22 | def hello(name: str) -> str: |
| 23 | """Say hello to someone.""" |
| 24 | return f"Hello, {name}!" |
| 25 | |
| 26 | if __name__ == "__main__": |
| 27 | mcp.run() # stdio transport (for Claude Code) |
| 28 | ``` |
| 29 | |
| 30 | Register in `.mcp.json`: |
| 31 | ```json |
| 32 | { |
| 33 | "mcpServers": { |
| 34 | "my-tool": { |
| 35 | "command": "python", |
| 36 | "args": ["my_server.py"] |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | ``` |
| 41 | |
| 42 | Restart Claude Code → `hello` tool appears natively. |
| 43 | |
| 44 | --- |
| 45 | |
| 46 | ## Type Annotations Matter |
| 47 | |
| 48 | Claude reads your type hints to understand the tool: |
| 49 | |
| 50 | ```python |
| 51 | @mcp.tool() |
| 52 | def search_files( |
| 53 | query: str, |
| 54 | directory: str = ".", |
| 55 | max_results: int = 10, |
| 56 | case_sensitive: bool = False, |
| 57 | ) -> list[str]: |
| 58 | """Search for files matching query in directory.""" |
| 59 | import subprocess |
| 60 | flag = "" if case_sensitive else "-i" |
| 61 | result = subprocess.run( |
| 62 | ["grep", "-rl", flag, query, directory], |
| 63 | capture_output=True, text=True |
| 64 | ) |
| 65 | return result.stdout.strip().split("\n")[:max_results] |
| 66 | ``` |
| 67 | |
| 68 | --- |
| 69 | |
| 70 | ## Wrap a CLI Tool |
| 71 | |
| 72 | ```python |
| 73 | import subprocess |
| 74 | from fastmcp import FastMCP |
| 75 | |
| 76 | mcp = FastMCP("git-helper") |
| 77 | |
| 78 | @mcp.tool() |
| 79 | def git_log(n: int = 10, format: str = "oneline") -> str: |
| 80 | """Show git commit history.""" |
| 81 | result = subprocess.run( |
| 82 | ["git", "log", f"-{n}", f"--format={format}"], |
| 83 | capture_output=True, text=True |
| 84 | ) |
| 85 | return result.stdout |
| 86 | |
| 87 | @mcp.tool() |
| 88 | def git_diff(staged: bool = False) -> str: |
| 89 | """Show git diff.""" |
| 90 | args = ["git", "diff"] |
| 91 | if staged: |
| 92 | args.append("--staged") |
| 93 | result = subprocess.run(args, capture_output=True, text=True) |
| 94 | return result.stdout |
| 95 | |
| 96 | if __name__ == "__main__": |
| 97 | mcp.run() |
| 98 | ``` |
| 99 | |
| 100 | --- |
| 101 | |
| 102 | ## Async Tools |
| 103 | |
| 104 | ```python |
| 105 | import asyncio |
| 106 | import httpx |
| 107 | from fastmcp import FastMCP |
| 108 | |
| 109 | mcp = FastMCP("web-fetcher") |
| 110 | |
| 111 | @mcp.tool() |
| 112 | async def fetch_url(url: str, timeout: int = 10) -> str: |
| 113 | """Fetch content from a URL.""" |
| 114 | async with httpx.AsyncClient() as client: |
| 115 | response = await client.get(url, timeout=timeout) |
| 116 | return response.text[:5000] # first 5k chars |
| 117 | |
| 118 | if __name__ == "__main__": |
| 119 | mcp.run() |
| 120 | ``` |
| 121 | |
| 122 | --- |
| 123 | |
| 124 | ## Resources (Read-Only Data) |
| 125 | |
| 126 | ```python |
| 127 | @mcp.resource("config://settings") |
| 128 | def get_settings() -> str: |
| 129 | """Return current settings.""" |
| 130 | import json, pathlib |
| 131 | settings = pathlib.Path("settings.json").read_text() |
| 132 | return settings |
| 133 | |
| 134 | @mcp.resource("file://{path}") |
| 135 | def read_file(path: str) -> str: |
| 136 | """Read a file by path.""" |
| 137 | return pathlib.Path(path).read_text() |
| 138 | ``` |
| 139 | |
| 140 | --- |
| 141 | |
| 142 | ## Prompts |
| 143 | |
| 144 | ```python |
| 145 | @mcp.prompt() |
| 146 | def code_review_prompt(code: str, language: str = "python") -> str: |
| 147 | """Generate a code review prompt.""" |
| 148 | return f"Review this {language} code for bugs and improvements:\n\n```{language}\n{code}\n```" |
| 149 | ``` |
| 150 | |
| 151 | --- |
| 152 | |
| 153 | ## HTTP Transport (for non-CC clients) |
| 154 | |
| 155 | ```python |
| 156 | if __name__ == "__main__": |
| 157 | mcp.run(transport="http", host="0.0.0.0", port=8080) |
| 158 | ``` |
| 159 | |
| 160 | Then register as: |
| 161 | ```json |
| 162 | {"mcpServers": {"my-tool": {"url": "http://localhost:8080/sse"}}} |
| 163 | ``` |
| 164 | |
| 165 | --- |
| 166 | |
| 167 | ## Error Handling |
| 168 | |
| 169 | ```python |
| 170 | @mcp.tool() |
| 171 | def risky_operation(value: str) -> str: |
| 172 | """Do something that might fail.""" |
| 173 | if not value: |
| 174 | raise ValueError("value cannot be empty") # MCP returns error to Claude |
| 175 | return process(value) |
| 176 | ``` |
| 177 | |
| 178 | --- |
| 179 | |
| 180 | ## Test Interactively |
| 181 | |
| 182 | ```bash |
| 183 | fastmcp dev my_server.py |
| 184 | # Opens interactive MCP inspector in browser |
| 185 | ``` |
| 186 | |
| 187 | --- |
| 188 | |
| 189 | ## With Environment Variables |
| 190 | |
| 191 | ```json |
| 192 | { |
| 193 | "mcpServers": { |
| 194 | "my-api": { |
| 195 | "command": "python", |
| 196 | "args": ["api_server.py"], |
| 197 | "env": { |
| 198 | "API_KEY": "your-secret-key", |
| 199 | "BASE_URL": "https://api.example.com" |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | ``` |