Skip to content

Commit e05543c

Browse files
committed
Implement MCP server integration
1 parent c8f45c5 commit e05543c

18 files changed

Lines changed: 1279 additions & 10 deletions

.sofosrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ src/
5656
│ ├── types.rs # Message types and serialization
5757
│ └── utils.rs # API utilities
5858
59+
├── mcp/ # MCP (Model Context Protocol) integration
60+
│ ├── mod.rs # MCP module exports
61+
│ ├── config.rs # MCP server configuration loading
62+
│ ├── protocol.rs # MCP protocol types (JSON-RPC, tools)
63+
│ ├── client.rs # MCP client implementations (stdio, HTTP)
64+
│ └── manager.rs # MCP server connection management
65+
5966
├── repl/ # REPL components
6067
│ ├── mod.rs # Main REPL loop and Repl struct
6168
│ ├── conversation.rs # Message history management

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sofos"
3-
version = "0.1.14"
3+
version = "0.1.15"
44
edition = "2021"
55

66
authors = ["Alexander Alexandrov"]

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
A blazingly fast, interactive AI coding assistant powered by Claude or GPT, implemented in pure Rust, that can generate code, edit files, and search the web - all from your terminal.
66

7+
Tested on macOS but should work on Linux and Windows as well.
8+
79
<div align="center"><img src="/assets/sofos_code.png" style="width: 800px;" alt="Sofos Code"></div>
810

911
## Table of Contents
@@ -20,6 +22,7 @@ A blazingly fast, interactive AI coding assistant powered by Claude or GPT, impl
2022
- [Custom Instructions](#custom-instructions)
2123
- [Session History](#session-history)
2224
- [Available Tools](#available-tools)
25+
- [MCP Servers](#mcp-servers)
2326
- [Security](#security)
2427
- [Configuration](#configuration)
2528
- [Development](#development)
@@ -178,10 +181,21 @@ Conversations auto-saved to `.sofos/sessions/`. Resume with `sofos -r` or `/resu
178181
**Image Vision:**
179182
- `image` - View and analyze images (JPEG, PNG, GIF, WebP)
180183
184+
**MCP Tools:**
185+
- Tools from configured MCP servers (prefixed with server name, e.g., `filesystem_read_file`)
186+
181187
**Note:** Only `read_file`, `list_directory`, and `image` can access paths outside workspace when explicitly allowed in config. All other operations are workspace-only.
182188
183189
Safe mode (`--safe-mode` or `/s`) restricts to: `list_directory`, `read_file`, `web_search`, `image`.
184190
191+
## MCP Servers
192+
193+
Connect to external tools via MCP (Model Context Protocol). Configure in `~/.sofos/config.toml` or `.sofos/config.local.toml` (see the example in the "Configuration" section).
194+
195+
Tools auto-discovered, prefixed with server name (e.g., `filesystem_read_file`). See `examples/mcp_quickstart.md`.
196+
197+
**Popular servers:** https://github.com/modelcontextprotocol/servers
198+
185199
## Security
186200
187201
**Sandboxing (by default):**
@@ -229,6 +243,24 @@ ask = [
229243
# Only for Bash commands (prompts for approval)
230244
"Bash(unknown_tool)",
231245
]
246+
247+
[mcpServers.company-internal]
248+
command = "/usr/local/bin/company-mcp-server"
249+
args = ["--config", "/etc/company/mcp-config.json"]
250+
env = { "COMPANY_API_URL" = "https://internal.company.com" }
251+
252+
[mcpServers.filesystem]
253+
command = "npx"
254+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
255+
256+
[mcpServers.github]
257+
command = "npx"
258+
args = ["-y", "@modelcontextprotocol/server-github"]
259+
env = { "GITHUB_TOKEN" = "ghp_YOUR_TOKEN" }
260+
261+
[mcpServers.api]
262+
url = "https://api.example.com/mcp"
263+
headers = { "Authorization" = "Bearer token123" }
232264
```
233265
234266
**Rules:**
@@ -263,6 +295,13 @@ src/
263295
│ ├── types.rs # Message types and serialization
264296
│ └── utils.rs # API utilities
265297
298+
├── mcp/ # MCP (Model Context Protocol) integration
299+
│ ├── mod.rs # MCP module exports
300+
│ ├── config.rs # MCP server configuration loading
301+
│ ├── protocol.rs # MCP protocol types (JSON-RPC, tools)
302+
│ ├── client.rs # MCP client implementations (stdio, HTTP)
303+
│ └── manager.rs # MCP server connection management
304+
266305
├── repl/ # REPL components
267306
│ ├── mod.rs # Main REPL loop
268307
│ ├── conversation.rs # Message history management

examples/config.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Sofos Configuration Example
2+
3+
# MCP Servers
4+
# Configure external tools via Model Context Protocol
5+
6+
# Filesystem server
7+
[mcpServers.filesystem]
8+
command = "npx"
9+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Documents"]
10+
11+
# Company internal server with environment variables
12+
[mcpServers.company-internal]
13+
command = "/usr/local/bin/company-mcp-server"
14+
args = ["--config", "/etc/company/mcp-config.json"]
15+
env = { "COMPANY_API_URL" = "https://internal.company.com" }
16+
17+
# Database with credentials
18+
[mcpServers.postgres]
19+
command = "npx"
20+
args = ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
21+
env = { "PGPASSWORD" = "secret123" }
22+
23+
# Remote API server (HTTP)
24+
[mcpServers.api]
25+
url = "https://api.example.com/mcp"
26+
headers = { "Authorization" = "Bearer token123" }
27+
28+
# Permissions
29+
[permissions]
30+
allow = [
31+
# Files outside workspace
32+
"Read(~/.zshrc)",
33+
"Read(~/.config/**)",
34+
35+
# Custom bash commands
36+
# "Bash(custom_command)",
37+
]
38+
39+
deny = [
40+
# Block specific files
41+
"Read(./.env)",
42+
"Read(./secrets/**)",
43+
]
44+
45+
ask = []

examples/mcp_examples.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# MCP Server Examples
2+
3+
Common MCP server configurations for Sofos.
4+
5+
## Filesystem
6+
7+
```toml
8+
[mcpServers.filesystem]
9+
command = "npx"
10+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
11+
```
12+
13+
## Databases
14+
15+
### PostgreSQL
16+
17+
```toml
18+
[mcpServers.postgres]
19+
command = "npx"
20+
args = ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
21+
```
22+
23+
### PostgreSQL with credentials
24+
25+
```toml
26+
[mcpServers.postgres]
27+
command = "npx"
28+
args = ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user@localhost/mydb"]
29+
env = { "PGPASSWORD" = "secret123" }
30+
```
31+
32+
### SQLite
33+
34+
```toml
35+
[mcpServers.sqlite]
36+
command = "npx"
37+
args = ["-y", "@modelcontextprotocol/server-sqlite", "/path/to/database.db"]
38+
```
39+
40+
## APIs
41+
42+
### GitHub
43+
44+
```toml
45+
[mcpServers.github]
46+
command = "npx"
47+
args = ["-y", "@modelcontextprotocol/server-github"]
48+
env = { "GITHUB_TOKEN" = "ghp_YOUR_TOKEN" }
49+
```
50+
51+
Get token: https://github.com/settings/tokens
52+
53+
### GitLab
54+
55+
```toml
56+
[mcpServers.gitlab]
57+
command = "npx"
58+
args = ["-y", "@modelcontextprotocol/server-gitlab"]
59+
env = { "GITLAB_TOKEN" = "glpat_YOUR_TOKEN" }
60+
```
61+
62+
### Slack
63+
64+
```toml
65+
[mcpServers.slack]
66+
command = "npx"
67+
args = ["-y", "@modelcontextprotocol/server-slack"]
68+
env = { "SLACK_BOT_TOKEN" = "xoxb-YOUR-TOKEN", "SLACK_TEAM_ID" = "T1234567890" }
69+
```
70+
71+
## Cloud Storage
72+
73+
### Google Drive
74+
75+
```toml
76+
[mcpServers.gdrive]
77+
command = "npx"
78+
args = ["-y", "@modelcontextprotocol/server-google-drive"]
79+
env = { "GOOGLE_APPLICATION_CREDENTIALS" = "/path/to/credentials.json" }
80+
```
81+
82+
## Custom Servers
83+
84+
### HTTP Server
85+
86+
```toml
87+
[mcpServers.custom]
88+
url = "https://api.example.com/mcp"
89+
headers = { "Authorization" = "Bearer YOUR_TOKEN" }
90+
```
91+
92+
### Python Server
93+
94+
```toml
95+
[mcpServers.python]
96+
command = "python"
97+
args = ["-m", "my_mcp_server"]
98+
env = { "API_KEY" = "YOUR_KEY" }
99+
```
100+
101+
### Custom Binary with Environment
102+
103+
```toml
104+
[mcpServers.company-internal]
105+
command = "/usr/local/bin/company-mcp-server"
106+
args = ["--config", "/etc/company/mcp-config.json"]
107+
env = { "COMPANY_API_URL" = "https://internal.company.com", "LOG_LEVEL" = "debug" }
108+
```
109+
110+
## Multiple Servers
111+
112+
```toml
113+
[mcpServers.docs]
114+
command = "npx"
115+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Documents"]
116+
117+
[mcpServers.projects]
118+
command = "npx"
119+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Projects"]
120+
121+
[mcpServers.github]
122+
command = "npx"
123+
args = ["-y", "@modelcontextprotocol/server-github"]
124+
env = { "GITHUB_TOKEN" = "ghp_YOUR_TOKEN" }
125+
```
126+
127+
## Config Locations
128+
129+
- **Global:** `~/.sofos/config.toml` - Shared across projects
130+
- **Local:** `.sofos/config.local.toml` - Project-specific (overrides global)
131+
132+
## Tool Naming
133+
134+
MCP tools are prefixed with their server name:
135+
- Server: `github`
136+
- Tool: `create_issue`
137+
- Available as: `github_create_issue`
138+
139+
## Resources
140+
141+
- All servers: https://github.com/modelcontextprotocol/servers
142+
- Documentation: https://modelcontextprotocol.io/

examples/mcp_quickstart.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# MCP Quick Start Guide
2+
3+
## What is MCP?
4+
5+
MCP (Model Context Protocol) allows Sofos to connect to external tools and services: databases, file systems, APIs, and more.
6+
7+
## Quick Setup
8+
9+
### 1. Install Node.js (if needed)
10+
11+
```bash
12+
# macOS
13+
brew install node
14+
15+
# Or visit: https://nodejs.org/
16+
```
17+
18+
### 2. Configure a Server
19+
20+
Create `~/.sofos/config.toml`:
21+
22+
```toml
23+
[mcpServers.filesystem]
24+
command = "npx"
25+
args = ["-y", "@modelcontextprotocol/server-filesystem", "/Users/yourusername/Documents"]
26+
```
27+
28+
### 3. Start Sofos
29+
30+
```bash
31+
sofos
32+
```
33+
34+
You should see: `MCP servers initialized`
35+
36+
### 4. Use MCP Tools
37+
38+
```
39+
λ> List files in my Documents folder
40+
41+
λ> Read test.txt from Documents
42+
```
43+
44+
The AI will use tools like `filesystem_list_directory` and `filesystem_read_file`.
45+
46+
## Popular Servers
47+
48+
### GitHub
49+
50+
```toml
51+
[mcpServers.github]
52+
command = "npx"
53+
args = ["-y", "@modelcontextprotocol/server-github"]
54+
env = { "GITHUB_TOKEN" = "ghp_YOUR_TOKEN" }
55+
```
56+
57+
Get token: https://github.com/settings/tokens
58+
59+
### PostgreSQL
60+
61+
```toml
62+
[mcpServers.postgres]
63+
command = "npx"
64+
args = ["-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
65+
```
66+
67+
### SQLite
68+
69+
```toml
70+
[mcpServers.sqlite]
71+
command = "npx"
72+
args = ["-y", "@modelcontextprotocol/server-sqlite", "/path/to/database.db"]
73+
```
74+
75+
## Config Locations
76+
77+
- **Global:** `~/.sofos/config.toml` - Shared across all projects
78+
- **Local:** `.sofos/config.local.toml` - Project-specific, overrides global
79+
80+
## More Servers
81+
82+
See all official servers: https://github.com/modelcontextprotocol/servers
83+
84+
## Troubleshooting
85+
86+
**Server won't start?**
87+
```bash
88+
# Test directly
89+
npx -y @modelcontextprotocol/server-filesystem /tmp
90+
```
91+
92+
**Tools not working?**
93+
- Check paths exist
94+
- Verify API tokens are valid
95+
- Ensure databases are running
96+
97+
## Resources
98+
99+
- Documentation: https://modelcontextprotocol.io/
100+
- Create your own: https://modelcontextprotocol.io/docs/building-servers

0 commit comments

Comments
 (0)