mcp

package
v0.1.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateTaskRequest

type CreateTaskRequest struct {
	Query    string   `json:"query" validate:"required,min=4,max=500"`
	SkillIDs []string `json:"skill_ids,omitempty" validate:"omitempty,max=5,dive,min=1,max=80"`
	MCPTools []string `json:"mcp_tools,omitempty" validate:"omitempty,max=5,dive,min=1,max=80"`
}

CreateTaskRequest POST /api/v1/mcp/create_task 请求体。

query 长度与 task.RecommendRequest 保持一致(4-500 字符)。

type GetAgentRequest

type GetAgentRequest struct {
	Slug string `json:"slug" validate:"required"`
}

GetAgentRequest POST /api/v1/mcp/get_agent 请求体。

slug 是市场 URL 中的人类可读 id(如 "translator-zh-en")。

type GetRunRequest

type GetRunRequest struct {
	RunID string `json:"run_id" validate:"required,uuid"`
}

GetRunRequest POST /api/v1/mcp/get_run 请求体。

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler /api/v1/mcp/* 路由。

路由组应挂 HybridAuthMiddleware:JWT 与访问令牌都能进, 但 handler 内强制只接受 user_token(assertUserTokenAuth),避免浏览器 cookie 误调。

func NewHandler

func NewHandler(svc service) *Handler

NewHandler 构造 MCP handler。

func (*Handler) GetEndpointInfo

func (h *Handler) GetEndpointInfo(c echo.Context) error

GetEndpointInfo 让浏览器打开 /api/v1/mcp 时能看到真实用法。 MCP 的独立 GET SSE stream 当前不实现;符合 Streamable HTTP 的 405 降级语义。

func (*Handler) GetTools

func (h *Handler) GetTools(c echo.Context) error

GetTools 列出工具描述。所有 5 个工具都列出来;客户端按 name 选择调用。

func (*Handler) PostCreateTask

func (h *Handler) PostCreateTask(c echo.Context) error

PostCreateTask 把自然语言任务转 task.Recommend,返回 Top 3 Agent 推荐。

func (*Handler) PostGetAgent

func (h *Handler) PostGetAgent(c echo.Context) error

PostGetAgent 详情。

func (*Handler) PostGetRun

func (h *Handler) PostGetRun(c echo.Context) error

PostGetRun 查 run 详情。

func (*Handler) PostRPC

func (h *Handler) PostRPC(c echo.Context) error

PostRPC exposes OpenLinker as an MCP server endpoint.

It implements the core JSON-RPC methods MCP clients need for tool discovery and invocation. Responses use application/json rather than SSE streaming.

func (*Handler) PostRunAgent

func (h *Handler) PostRunAgent(c echo.Context) error

PostRunAgent 同步调用。把 source 设为 'mcp'。

func (*Handler) PostSearchAgents

func (h *Handler) PostSearchAgents(c echo.Context) error

PostSearchAgents 市场搜索。

func (*Handler) Register

func (h *Handler) Register(api *echo.Group, mw echo.MiddlewareFunc)

Register 挂载所有 MCP 路由。

GET  /mcp                 入口说明;若客户端请求 SSE stream,返回 405
POST /mcp                 MCP Streamable HTTP JSON-RPC(JSON response mode)
GET  /mcp/tools           工具元信息
POST /mcp/search_agents   市场搜索
POST /mcp/get_agent       Agent 详情
POST /mcp/run_agent       调用 Agent(写 runs.source='mcp')
POST /mcp/get_run         查询调用结果
POST /mcp/create_task     自然语言 → 推荐 Agent

type RunAgentRequest

type RunAgentRequest struct {
	AgentID  string                 `json:"agent_id" validate:"required,uuid"`
	Input    map[string]interface{} `json:"input" validate:"required"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

RunAgentRequest POST /api/v1/mcp/run_agent 请求体。

agent_id 是 UUID;input 透传给创作者 endpoint。

type SearchAgentsRequest

type SearchAgentsRequest struct {
	Query string   `json:"query,omitempty"`
	Tags  []string `json:"tags,omitempty"`
	Limit int32    `json:"limit,omitempty"`
}

SearchAgentsRequest POST /api/v1/mcp/search_agents 请求体。

全部可选;不传任何字段时返回默认市场首页。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 极薄 facade,把 MCP 5 个工具直接转到既有 service。 不重新初始化任何依赖:main.go 把现成的 *MarketService / *runtime.Service / *task.Service 直接注入。

func NewService

func NewService(market *agent.MarketService, runtimeSvc *runtime.Service, taskSvc *task.Service) *Service

NewService 构造 MCP service。

func (*Service) CreateTask

func (s *Service) CreateTask(ctx context.Context, userID uuid.UUID, req *CreateTaskRequest) (*task.RecommendResponse, error)

CreateTask 把自然语言任务交给 task.Recommend,返回解析出的 skill + 推荐 Agent。 客户端拿到推荐后通常用 run_agent 实际调用。

func (*Service) GetAgent

GetAgent 转 market.GetBySlug;返回结构里已经包含 capability / examples。

func (*Service) GetRun

func (s *Service) GetRun(ctx context.Context, userID, runID uuid.UUID) (*runtime.RunResponse, error)

GetRun 转 runtime.GetRun(owner 校验在 service 内做)。

func (*Service) RunAgent

func (s *Service) RunAgent(ctx context.Context, userID uuid.UUID, req *RunAgentRequest) (*runtime.RunResponse, error)

RunAgent 转 runtime.Run,并标记 source='mcp',让 /usage 能识别来源。

func (*Service) SearchAgents

func (s *Service) SearchAgents(ctx context.Context, req *SearchAgentsRequest) (*agent.MarketListResponse, error)

SearchAgents 转 market.ListMarket,按 query/tags 过滤。

func (*Service) Tools

func (s *Service) Tools() []ToolDescriptor

Tools 返回工具描述,硬编码常量;MCP 客户端用 InputSchema 决定参数表单。

type ToolDescriptor

type ToolDescriptor struct {
	Name         string                 `json:"name"`
	Description  string                 `json:"description"`
	InputSchema  map[string]interface{} `json:"input_schema"`
	OutputSchema map[string]interface{} `json:"output_schema,omitempty"`
}

ToolDescriptor 暴露给 MCP 客户端的工具元信息。

客户端用 InputSchema 决定参数表单 / 校验;OutputSchema 留作 hint,不强制校验。

type ToolsResponse

type ToolsResponse struct {
	Tools []ToolDescriptor `json:"tools"`
}

ToolsResponse GET /api/v1/mcp/tools 响应。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL