mcpserver

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

handlers.go implements MCP tool handlers that bridge MCP protocol calls to servicecore operations. This file contains the actual tool implementations that process MCP requests and format responses.

Tool Implementation Pattern: 1. Extract and validate parameters from MCP request 2. Extract client ID from MCP context for multi-tenant operation 3. Call appropriate servicecore method with client scoping 4. Format response for MCP client consumption 5. Handle errors with structured MCP error responses

Multi-Tenant Support Status: - The servicecore layer is designed for multi-tenant operation with client isolation - However, actual client ID extraction from MCP context is not yet implemented - Currently all MCP clients use the same DEFAULT_CLIENT_ID, making them effectively global - This means MCP clients can see and interact with each other's sessions

Security Considerations: - All operations require valid client ID from MCP context - Parameter validation prevents malicious input - Errors are logged but sanitized for client responses - Client isolation is enforced through servicecore operations (when client IDs differ)

server.go implements the MCP (Model Context Protocol) server for cagent's multi-tenant architecture. This component provides the transport layer that bridges MCP clients with cagent's servicecore business logic.

Core Responsibilities: 1. MCP Protocol Implementation:

  • Registers MCP tools (invoke_agent, list_agents, pull_agent, session management)
  • Handles MCP client connections and lifecycle events
  • Provides structured error responses following MCP conventions
  • Manages real client IDs extracted from MCP session context

2. Client Lifecycle Management:

  • OnClientConnect: Creates new client in servicecore with real MCP client ID
  • OnClientDisconnect: Removes client and cleans up all associated sessions
  • Client ID validation and uniqueness enforcement
  • Automatic resource cleanup on disconnect

3. Tool Registration and Routing:

  • Maps MCP tool calls to servicecore operations
  • Handles parameter validation and type conversion
  • Provides consistent error handling across all tools
  • Formats responses for MCP client consumption

4. Security and Isolation:

  • Enforces client isolation through servicecore operations
  • Validates all client operations against proper client context
  • Prevents cross-client access through MCP protocol violations
  • Logs security-relevant events for monitoring

Integration Architecture: - Uses servicecore.ServiceManager for all business logic - Leverages mcp-go library for protocol implementation - Provides clean separation between transport and business logic - Enables consistent behavior across MCP and future HTTP transports

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MCPServer

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

MCPServer implements the MCP server using servicecore for business logic

func NewMCPServer

func NewMCPServer(serviceCore servicecore.ServiceManager, basePath string) *MCPServer

NewMCPServer creates a new MCP server instance

func (*MCPServer) Start

func (s *MCPServer) Start(ctx context.Context, port string) error

Start starts the MCP SSE server on the specified port

Jump to

Keyboard shortcuts

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