Skip to content

Commit 6478b97

Browse files
authored
Feat/mcp client support (#59)
1 parent f24666f commit 6478b97

17 files changed

Lines changed: 3135 additions & 34 deletions

GitAgent_Redesigned.pptx

42.1 KB
Binary file not shown.

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,70 @@ my-plugin/
607607
└── index.ts # Programmatic entry point
608608
```
609609

610+
## MCP (Model Context Protocol)
611+
612+
Gitagent is an **MCP client**: point it at any [MCP server](https://modelcontextprotocol.io) and that server's tools are automatically discovered and made available to the agent — no integration code to write. This unlocks the whole ecosystem of ready-made servers (filesystem, GitHub, Postgres, Slack, fetch, …).
613+
614+
### Configure servers in `agent.yaml`
615+
616+
```yaml
617+
mcp_servers:
618+
filesystem: # local server over stdio (default)
619+
command: npx
620+
args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/data"]
621+
env:
622+
LOG_LEVEL: "${MCP_LOG_LEVEL}" # ${VAR} interpolated from the environment
623+
timeoutMs: 30000 # connect/list timeout (default 30000)
624+
625+
analytics: # remote server over Streamable HTTP
626+
type: http
627+
url: "https://mcp.example.com/mcp"
628+
headers:
629+
Authorization: "Bearer ${ANALYTICS_TOKEN}"
630+
631+
legacy: # legacy SSE transport (deprecated)
632+
type: sse
633+
url: "https://old.example.com/sse"
634+
```
635+
636+
On startup gitagent connects to each server, lists its tools, and registers them as **`<server>__<tool>`** (e.g. `filesystem__read_file`, `analytics__query`). Connections are torn down automatically when the session ends.
637+
638+
| Field | Applies to | Description |
639+
|---|---|---|
640+
| `command` / `args` / `env` / `cwd` | stdio | How to launch a local server |
641+
| `type: http \| sse` + `url` + `headers` | remote | Connect to a remote server |
642+
| `timeoutMs` | both | Connect + list-tools timeout (default `30000`) |
643+
644+
### Use via the SDK
645+
646+
```typescript
647+
import { query } from "gitagent";
648+
649+
for await (const msg of query({
650+
prompt: "Summarize last week's signups from the database",
651+
mcpServers: {
652+
postgres: {
653+
command: "npx",
654+
args: ["-y", "@modelcontextprotocol/server-postgres", process.env.DB_URL!],
655+
},
656+
},
657+
})) {
658+
if (msg.type === "tool_use") console.log(`calling ${msg.toolName}`);
659+
}
660+
```
661+
662+
SDK `mcpServers` are merged with any `agent.yaml` `mcp_servers` (the SDK value wins on a key collision).
663+
664+
### Behavior & guarantees
665+
666+
- **Fail-soft:** a server that can't start (or times out) is logged and skipped — other servers and built-in tools keep working.
667+
- **Namespaced & sanitized:** tool names are prefixed with the server name and cleaned to satisfy provider naming rules.
668+
- **Pagination:** servers that paginate their tool list are fully enumerated.
669+
- **Cleanup:** stdio servers (child processes) are shut down on every exit path (normal, `/quit`, Ctrl+C, error).
670+
- **Lazy:** if no servers are configured, the MCP SDK is never loaded.
671+
672+
> Note: v1 supports MCP **tools**. Resources and prompts are not yet exposed.
673+
610674
## Multi-Model Support
611675

612676
Gitagent works with any LLM provider supported by [pi-ai](https://github.com/badlogic/pi-mono/tree/main/packages/ai):

0 commit comments

Comments
 (0)