Files
opsxdb/server/cmd/opsxdb-mcp/main.go
T
logan 2336c9433c feat(ai): Agent SSE + Anthropic/responses tools + P1 确认写
- Agent 支持 SSE(步骤边推、正文分块),JSON 非流式 fallback
- tool calling 覆盖 openai-chat / anthropic / responses(单测解析回灌)
- P1:mcp.json mode=read_write 才可写;需 confirm_danger;Agent 剥离模型自带令牌
- GET /api/ai/mcp-status、POST /api/ai/agent/confirm;审计 source=mcp|agent
2026-10-15 13:00:40 +08:00

56 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// opsxdb-mcp:stdio MCP Server,暴露只读数据库工具(P0)。 // Logan.Li
//
// 配置:
// ~/.opsxdb/mcp.json — allowed_connection_ids;mode(P0 执行层强制只读)
// ~/.opsxdb/connections.json — 桌面双写的连接列表(密码 ox1. 混淆)
// ~/.opsxdb/logs/mcp-audit.jsonl
//
// Cursor 示例见 docs/mcp-cursor.example.json
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
"opsxdb/server/internal/aitools"
)
func main() {
rt, err := aitools.DefaultRuntime()
if err != nil {
fmt.Fprintf(os.Stderr, "opsxdb-mcp: load policy: %v\n", err)
os.Exit(1)
}
rt.Source = "mcp"
s := server.NewMCPServer(
"opsxdb",
"0.1.0",
server.WithToolCapabilities(true),
)
for _, spec := range aitools.ToolSpecs() {
raw, _ := json.Marshal(spec.InputSchema())
t := mcp.NewToolWithRawSchema(spec.Name, spec.Description, raw)
toolName := spec.Name
s.AddTool(t, func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
args := req.GetArguments()
out, err := rt.Call(ctx, toolName, args)
if err != nil {
return mcp.NewToolResultError(err.Error()), nil
}
return mcp.NewToolResultText(aitools.ResultJSON(out)), nil
})
}
if err := server.ServeStdio(s); err != nil {
fmt.Fprintf(os.Stderr, "opsxdb-mcp: %v\n", err)
os.Exit(1)
}
}