added auth to remote mcps
This commit is contained in:
@@ -54,8 +54,6 @@ This file defines your models, MCP servers, and agent profiles.
|
||||
tool_response_threshold = 10000 # Bytes after which tool results are buffered to files
|
||||
|
||||
[models.default]
|
||||
```
|
||||
|
||||
model_id = "env:DEFAULT_MODEL_ID"
|
||||
endpoint = "env:DEFAULT_MODEL_ENDPOINT"
|
||||
api_key = "env:DEFAULT_MODEL_API_KEY"
|
||||
@@ -67,6 +65,12 @@ transport = "stdio"
|
||||
command = "npx"
|
||||
args = ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
||||
|
||||
[mcp_servers.remote_tools]
|
||||
transport = "sse"
|
||||
url = "https://api.example.com/mcp"
|
||||
auth_token = "env:MCP_API_KEY" # Optional Bearer token
|
||||
headers = { "X-Custom-Header" = "value" } # Optional custom headers
|
||||
|
||||
[agents.coordinator]
|
||||
role = "COORDINATOR"
|
||||
model_id = "default"
|
||||
@@ -105,6 +109,26 @@ user's request and delegate tasks accordingly.
|
||||
./bin/sidekick-tui
|
||||
```
|
||||
|
||||
### Running the Sidekick MCP Server
|
||||
|
||||
Sidekick can also act as an MCP server, allowing other LLM-powered applications to leverage its agentic capabilities.
|
||||
|
||||
1. Configure the `mcp_listener` in `config.toml`:
|
||||
|
||||
```toml
|
||||
[mcp_listener]
|
||||
transport = "sse" # "stdio" or "sse"/"http"
|
||||
port = 8080 # for sse/http
|
||||
```
|
||||
|
||||
2. Run the MCP server:
|
||||
|
||||
```bash
|
||||
./bin/sidekick-mcp
|
||||
```
|
||||
|
||||
The server provides a `query` tool that routes requests to your coordinator agent, maintaining conversation history if provided.
|
||||
|
||||
* **Input:** Type your messages at the bottom prompt.
|
||||
* **Send:** Press `Enter` to send a message.
|
||||
* **Quit:** Press `ctrl+c` to exit.
|
||||
|
||||
@@ -41,6 +41,8 @@ type MCPServerConfig struct {
|
||||
Args []string `toml:"args"` // for stdio
|
||||
Env []string `toml:"env"` // for stdio, format "KEY=VALUE"
|
||||
URL string `toml:"url"` // for HTTP/SSE/WebSocket
|
||||
AuthToken string `toml:"auth_token"` // for HTTP Bearer authentication
|
||||
Headers map[string]string `toml:"headers"` // for custom headers
|
||||
}
|
||||
|
||||
// AgentConfig holds configuration for a specific agent instance
|
||||
@@ -66,6 +68,14 @@ func resolveEnv(val string) string {
|
||||
return val
|
||||
}
|
||||
|
||||
func (s *MCPServerConfig) Resolve() {
|
||||
s.URL = resolveEnv(s.URL)
|
||||
s.AuthToken = resolveEnv(s.AuthToken)
|
||||
for k, v := range s.Headers {
|
||||
s.Headers[k] = resolveEnv(v)
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve applies environment variable resolution to relevant fields
|
||||
func (m *ModelConfig) Resolve() {
|
||||
m.ModelID = resolveEnv(m.ModelID)
|
||||
@@ -92,6 +102,10 @@ func LoadConfig(path string) (*ProjectConfig, error) {
|
||||
m.Resolve()
|
||||
cfg.Models[k] = m
|
||||
}
|
||||
for k, s := range cfg.MCPServers {
|
||||
s.Resolve()
|
||||
cfg.MCPServers[k] = s
|
||||
}
|
||||
for k, a := range cfg.Agents {
|
||||
a.ID = k
|
||||
a.ToolResponseThreshold = cfg.ToolResponseThreshold
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mark3labs/mcp-go/client"
|
||||
"github.com/mark3labs/mcp-go/client/transport"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
)
|
||||
|
||||
@@ -71,9 +72,31 @@ var defaultMCPFactory MCPClientFactory = func(toolset string) (MCPClientInterfac
|
||||
case "stdio":
|
||||
c, err = client.NewStdioMCPClient(cfg.Command, cfg.Env, cfg.Args...)
|
||||
case "sse":
|
||||
c, err = client.NewSSEMCPClient(cfg.URL)
|
||||
var opts []transport.ClientOption
|
||||
headers := make(map[string]string)
|
||||
if cfg.AuthToken != "" {
|
||||
headers["Authorization"] = "Bearer " + cfg.AuthToken
|
||||
}
|
||||
for k, v := range cfg.Headers {
|
||||
headers[k] = v
|
||||
}
|
||||
if len(headers) > 0 {
|
||||
opts = append(opts, transport.WithHeaders(headers))
|
||||
}
|
||||
c, err = client.NewSSEMCPClient(cfg.URL, opts...)
|
||||
case "http":
|
||||
c, err = client.NewStreamableHttpClient(cfg.URL)
|
||||
var opts []transport.StreamableHTTPCOption
|
||||
headers := make(map[string]string)
|
||||
if cfg.AuthToken != "" {
|
||||
headers["Authorization"] = "Bearer " + cfg.AuthToken
|
||||
}
|
||||
for k, v := range cfg.Headers {
|
||||
headers[k] = v
|
||||
}
|
||||
if len(headers) > 0 {
|
||||
opts = append(opts, transport.WithHTTPHeaders(headers))
|
||||
}
|
||||
c, err = client.NewStreamableHttpClient(cfg.URL, opts...)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported MCP transport: %s", cfg.Transport)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user