|
| 1 | +# Model Context Protocol |
| 2 | + |
| 3 | +Nerve supports [MCP](https://modelcontextprotocol.io/introduction) both as a client and as a server: |
| 4 | + |
| 5 | +* [Client](#mcp-client) |
| 6 | +* [Server](#mcp-server) |
| 7 | + - [Serving an Agent](#serving-an-agent) |
| 8 | + - [Serving an Agent and its Tools](#serving-an-agent-and-its-tools) |
| 9 | + - [Tools Only](#tools-only) |
| 10 | + |
| 11 | +## MCP Client |
| 12 | + |
| 13 | +An agent can use any server from [the multitude of publicly available MPC servers](https://github.com/punkpeye/awesome-mcp-servers) with: |
| 14 | + |
| 15 | +```yaml |
| 16 | +agent: You are a helpful assistant. |
| 17 | +task: Write something to your knowledge graph, then read it back, save it to output.txt and set your task as complete. |
| 18 | + |
| 19 | +using: |
| 20 | + - task |
| 21 | + |
| 22 | +mcp: |
| 23 | + memory: |
| 24 | + command: npx |
| 25 | + args: ["-y", "@modelcontextprotocol/server-memory"] |
| 26 | + |
| 27 | + filesystem: |
| 28 | + command: npx |
| 29 | + args: ["-y", "@modelcontextprotocol/server-filesystem", "."] |
| 30 | +``` |
| 31 | +
|
| 32 | +## MCP Server |
| 33 | +
|
| 34 | +Nerve can also act as a MCP server via the `nerve serve <agent>` command. In this mode you can turn an agent into a tool for other agents to use. |
| 35 | + |
| 36 | +### Serving an Agent |
| 37 | + |
| 38 | +For instance this command line will serve the [code-audit](https://github.com/evilsocket/code-audit) agent as an MCP server: |
| 39 | + |
| 40 | +```bash |
| 41 | +nerve serve code-audit --mcp |
| 42 | +``` |
| 43 | + |
| 44 | +This means that agents can use other agents as tools, for instance: |
| 45 | + |
| 46 | +```yaml |
| 47 | +agent: You are a helpful assistant. |
| 48 | +task: Perform a code audit of {{ path }}. |
| 49 | +
|
| 50 | +using: |
| 51 | + - task |
| 52 | +
|
| 53 | +mcp: |
| 54 | + code_audit: |
| 55 | + command: nerve |
| 56 | + args: ["serve", "code-audit", "--mcp"] |
| 57 | +``` |
| 58 | + |
| 59 | +You can find a full [example here](https://github.com/evilsocket/nerve/tree/main/examples/mcp-recipe). |
| 60 | + |
| 61 | +### Serving an Agent and its Tools |
| 62 | + |
| 63 | +Additionally you can also serve the agent tools: |
| 64 | + |
| 65 | +```bash |
| 66 | +nerve serve code-audit --mcp -t |
| 67 | +``` |
| 68 | + |
| 69 | +This will export both the agent itself and its tools via MCP. |
| 70 | + |
| 71 | +### Tools Only |
| 72 | + |
| 73 | +You can use this mechanism to serve simple tools via MCP as well. For instance if you create a `tools.yml` like this: |
| 74 | + |
| 75 | +```yaml |
| 76 | +tools: |
| 77 | + - name: get_weather |
| 78 | + description: Get the current weather in a given place. |
| 79 | + arguments: |
| 80 | + - name: place |
| 81 | + description: The place to get the weather of. |
| 82 | + example: Rome |
| 83 | + tool: curl wttr.in/{{ place }} |
| 84 | +``` |
| 85 | + |
| 86 | +You can serve it via MCP with: |
| 87 | + |
| 88 | +```bash |
| 89 | +nerve serve tools.yml --mcp |
| 90 | +``` |
0 commit comments