Il Model Context Protocol (MCP) permette a Gravity di collegarsi a server di strumenti esterni. Gli agenti MCP compaiono accanto a quelli integrati e l'LLM può richiamarli durante l'esecuzione dei compiti.
Configurazione
Configura i server MCP in settings.json sotto McpServers:
{
"McpServers": {
"filesystem": {
"name": "filesystem",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "C:\\workspace"]
},
"github": {
"name": "github",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..." }
}
}
}
| Field | Tipo | Descrizione |
|---|---|---|
name | string | Unique server identifier |
command | string | Executable to spawn (e.g., npx, python, uvx) |
args | string[] | Command arguments |
env | object | Environment variables for the process |
Protocollo JSON-RPC
MCP agents communicate via stdio JSON-RPC 2.0. The McpClient handles:
- Process spawning and lifecycle management
- Message framing (newline-delimited JSON)
- Request/response correlation via IDs
- Capability negotiation on initialization
- Tool/list_resources/list_prompts discovery
- Automatic reconnection on crash
Wrapper McpAgent
La pipeline McpAgent wraps an MCP server as an IAgent:
- Exposes MCP tools through standard
AgentDescriptor - Routes calls via
ReasoningRouter(same as built-in agents) - Handles parameter validation and approval policies
- Supports both tools and resources
MCP tools appear in the LLM's tool manifest with namespaced names like mcp_filesystem.read_file.
Esempio: server del file system
Install the official MCP filesystem server:
npm install -g @modelcontextprotocol/server-filesystem
Add to settings.json:
"McpServers": {
"local-fs": {
"name": "local-fs",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "C:\\Users\\YourName\\projects"]
}
}
After restart, the agent mcp_local-fs will be available with tools:
read_file,write_file,list_directorycreate_directory,move_file,search_filesget_file_info
Usage: "Use the filesystem agent to list my project files"