Le Model Context Protocol (MCP) permet à Gravity de se connecter à des serveurs d'outils externes. Les agents MCP apparaissent à côté des agents intégrés et le LLM peut les appeler pendant l'exécution des tâches.
Configuration
Configurez les serveurs MCP dans settings.json sous 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 | Type | Description |
|---|---|---|
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 |
Protocole 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
Enveloppe McpAgent
Le 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.
Exemple : serveur de système de fichiers
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"