mcpbridge

package
v0.35.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package mcpbridge implements a stdio MCP server that exposes agentserver agent discovery and task delegation as MCP tools for Claude Code.

Protocol: JSON-RPC 2.0 over stdin/stdout (newline-delimited). Methods: initialize, notifications/initialized, tools/list, tools/call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunMCPServer

func RunMCPServer()

RunMCPServer is the entry point for the `agentserver mcp-server` subcommand. Reads config from env vars and runs the MCP stdio server.

Types

type AgentListing

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

AgentListing periodically fetches the available agent list and formats it for injection into the delegate_task tool description.

func NewAgentListing

func NewAgentListing(serverURL, token, workspaceID, selfID string) *AgentListing

NewAgentListing creates a new listing that will poll for agents.

func (*AgentListing) FormatForToolDescription

func (l *AgentListing) FormatForToolDescription() string

FormatForToolDescription generates the agent list appended to delegate_task description.

func (*AgentListing) Refresh

func (l *AgentListing) Refresh() error

Refresh fetches the latest agent list from the server.

func (*AgentListing) Start

func (l *AgentListing) Start(ctx context.Context)

Start begins periodic refresh. Call once on startup.

type Bridge

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

Bridge is the MCP bridge server connecting Claude Code to agentserver.

func NewBridge

func NewBridge(cfg BridgeConfig) *Bridge

NewBridge creates a new MCP bridge.

func (*Bridge) HandleTool

func (b *Bridge) HandleTool(name string, args json.RawMessage) (*ToolResult, error)

HandleTool dispatches a tool call to the appropriate handler.

func (*Bridge) StartListing

func (b *Bridge) StartListing(ctx context.Context)

StartListing begins periodic agent listing refresh.

func (*Bridge) Tools

func (b *Bridge) Tools() []ToolDef

Tools returns the MCP tool definitions.

type BridgeConfig

type BridgeConfig struct {
	ServerURL   string
	Token       string // tunnel_token or proxy_token
	WorkspaceID string
	SandboxID   string // self (exclude from discovery)
}

BridgeConfig holds the agentserver connection settings.

type DiscoveredAgent

type DiscoveredAgent struct {
	AgentID     string `json:"agent_id"`
	DisplayName string `json:"display_name"`
	Description string `json:"description"`
	AgentType   string `json:"agent_type"`
	Status      string `json:"status"`
	Card        struct {
		Tags   []string `json:"tags"`
		Skills []struct {
			Name        string `json:"name"`
			Description string `json:"description"`
		} `json:"skills"`
	} `json:"card"`
}

DiscoveredAgent is an agent from the discovery API.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error is a JSON-RPC 2.0 error object.

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id,omitempty"` // absent for notifications; "null" is valid request id
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is a JSON-RPC 2.0 request or notification.

func (*Request) IsNotification

func (r *Request) IsNotification() bool

IsNotification returns true if this is a notification (no id field).

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id"`
	Result  any             `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Response is a JSON-RPC 2.0 response.

type Server

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

Server handles JSON-RPC 2.0 messages on stdin/stdout.

func NewServer

func NewServer(tools []ToolDef, handler func(string, json.RawMessage) (*ToolResult, error)) *Server

NewServer creates an MCP stdio server.

func (*Server) Run

func (s *Server) Run() error

Run reads requests from stdin and writes responses to stdout. Blocks until EOF.

type ToolDef

type ToolDef struct {
	Name string

	InputSchema map[string]any
	Annotations map[string]any
	// contains filtered or unexported fields
}

ToolDef defines an MCP tool.

func (*ToolDef) Description

func (t *ToolDef) Description() string

Description returns the tool description, using dynamic if available.

type ToolResult

type ToolResult struct {
	Content []map[string]string `json:"content"`
	IsError bool                `json:"isError,omitempty"`
}

ToolResult is the MCP tool call result.

Jump to

Keyboard shortcuts

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