Documentation
¶
Overview ¶
Package mcp provides MCP (Model Context Protocol) server implementation for LangGraph workflows.
This file implements prompt template management, including registration, listing, and rendering with parameter substitution.
Index ¶
- Constants
- Variables
- func MarshalErrorResponse(id any, code int, message string, data any) ([]byte, error)
- func MarshalRequest(id any, method string, params any) ([]byte, error)
- func MarshalResourcesListResult(resources []ResourceInfo) (interface{}, error)
- func MarshalResourcesReadResult(uri, mimeType string, content []byte) (interface{}, error)
- func MarshalResponse(id any, result any) ([]byte, error)
- func ParseResourceContent(rc ResourceContent) ([]byte, error)
- type Capabilities
- type ClientInfo
- type ConnectionSession
- type Content
- type ContentBlock
- type DynamicResource
- type Error
- type InitializeRequest
- type InitializeResponse
- type MCPServer
- type Message
- type PromptInfo
- type PromptParameter
- type PromptRegistry
- type PromptTemplate
- type RegisteredTool
- type RegistryOption
- type RenderedPrompt
- type Request
- type Resource
- type ResourceContent
- type ResourceInfo
- type ResourceProvider
- type ResourceProviderOption
- type ResourcesListResult
- type ResourcesReadParams
- type ResourcesReadResult
- type Response
- type ServerConfig
- type ServerInfo
- type StaticResource
- type ToolAdapterMetadata
- type ToolMetadata
- type ToolRegistry
- type ToolResult
Constants ¶
const ( // ErrCodeParseError indicates invalid JSON was received by the server. ErrCodeParseError = -32700 // ErrCodeInvalidRequest indicates the JSON sent is not a valid Request object. ErrCodeInvalidRequest = -32600 // ErrCodeMethodNotFound indicates the method does not exist or is not available. ErrCodeMethodNotFound = -32601 // ErrCodeInvalidParams indicates invalid method parameter(s). ErrCodeInvalidParams = -32602 // ErrCodeInternalError indicates internal JSON-RPC error. ErrCodeInternalError = -32603 )
JSON-RPC 2.0 standard error codes as defined in the specification.
const ( // StateUninitialized indicates the server has been created but not started. StateUninitialized int32 = iota // StateInitializing indicates the server is performing startup initialization. StateInitializing // StateRunning indicates the server is actively processing requests. StateRunning // StateStopped indicates the server has been stopped and cannot be restarted. StateStopped )
Server lifecycle states represent the operational state of the MCP server.
const DefaultMaxResourceSize = 10 * 1024 * 1024 // 10MB
DefaultMaxResourceSize is the default maximum size for resources (10MB)
Variables ¶
var ( ErrPromptNotFound = errors.New("prompt not found") ErrPromptAlreadyExists = errors.New("prompt already registered") ErrInvalidPromptName = errors.New("prompt name must match pattern ^[a-z][a-z0-9_]*$") ErrInvalidParameterName = errors.New("parameter name must match pattern ^[a-z][a-z0-9_]*$") ErrDuplicateParameterName = errors.New("duplicate parameter name") ErrEmptyTemplate = errors.New("prompt template cannot be empty") ErrMissingParameter = errors.New("missing required parameter") ErrUndefinedPlaceholder = errors.New("template contains placeholder with no matching parameter") )
Errors returned by PromptRegistry operations
var ( ErrResourceNotFound = errors.New("resource not found") ErrInvalidResourceURI = errors.New("invalid resource URI") ErrResourceAlreadyExists = errors.New("resource already exists") ErrResourceTooLarge = errors.New("resource exceeds size limit") ErrEmptyName = errors.New("resource name cannot be empty") ErrInvalidGenerator = errors.New("generator function cannot be nil") )
Errors for resource operations
var ( ErrToolNotFound = errors.New("tool not found") ErrInvalidToolName = errors.New("invalid tool name") ErrDuplicateToolName = errors.New("duplicate tool name") ErrEmptyDescription = errors.New("description cannot be empty") ErrNilInputSchema = errors.New("inputSchema cannot be nil") ErrToolNameMismatch = errors.New("tool name does not match metadata name") )
Common errors
var ( // ErrServerNotRunning is returned when attempting operations that require // the server to be in a specific state. ErrServerNotRunning = errors.New("server is not running") )
Server errors for resource registration and lifecycle management.
Functions ¶
func MarshalErrorResponse ¶
MarshalErrorResponse creates a JSON-RPC 2.0 error response with the given error. This is a convenience function for creating well-formed error responses.
func MarshalRequest ¶
MarshalRequest creates a JSON-RPC 2.0 request with the given parameters. This is a convenience function for creating well-formed requests.
func MarshalResourcesListResult ¶
func MarshalResourcesListResult(resources []ResourceInfo) (interface{}, error)
MarshalResourcesListResult creates the JSON-RPC result for resources/list
func MarshalResourcesReadResult ¶
MarshalResourcesReadResult creates the JSON-RPC result for resources/read
func MarshalResponse ¶
MarshalResponse creates a JSON-RPC 2.0 success response with the given result. This is a convenience function for creating well-formed responses.
func ParseResourceContent ¶
func ParseResourceContent(rc ResourceContent) ([]byte, error)
ParseResourceContent parses ResourceContent back to bytes
Types ¶
type Capabilities ¶
type Capabilities struct {
// Tools indicates whether the implementation supports tool/function calling.
Tools bool `json:"tools,omitempty"`
// Resources indicates whether the implementation supports resource access.
Resources bool `json:"resources,omitempty"`
// Prompts indicates whether the implementation supports prompt templates.
Prompts bool `json:"prompts,omitempty"`
}
Capabilities describes the optional features supported by a client or server. Used during the initialization handshake to negotiate supported features.
type ClientInfo ¶
type ClientInfo struct {
// Name is the name of the client implementation.
Name string `json:"name"`
// Version is the version of the client implementation.
Version string `json:"version"`
}
ClientInfo describes the client implementation making the MCP request. Used in the initialize method to identify the client.
type ConnectionSession ¶
type ConnectionSession struct {
// ClientInfo contains information about the connected client (from initialize request).
ClientInfo map[string]interface{}
// ProtocolVersion is the MCP protocol version negotiated during initialization.
ProtocolVersion string
// Capabilities lists the client's declared capabilities (if provided).
Capabilities map[string]interface{}
// ConnectionTime records when the connection was established.
ConnectionTime int64 // Unix timestamp in nanoseconds
}
ConnectionSession represents an active MCP client connection.
For stdio transport, there is typically one connection session per server instance. This struct tracks metadata about the connected client for observability and debugging.
type Content ¶
type Content struct {
Type string // "text", "image", or "resource"
Text string // For type="text"
Data string // For type="image" (base64 encoded)
MimeType string // For type="image"
Resource string // For type="resource" (resource URI)
}
Content represents message content with different types. Type determines which fields are populated.
type ContentBlock ¶
type ContentBlock struct {
Type string // "text", "image", "resource"
Text string
Data string // Base64 for images
MimeType string
Resource string // Resource URI
}
ContentBlock represents a content item in tool results.
type DynamicResource ¶
type DynamicResource struct {
// contains filtered or unexported fields
}
DynamicResource represents a resource with computed content
func NewDynamicResource ¶
func NewDynamicResource(uri, name, description, mimeType string, generator func(context.Context) ([]byte, error)) *DynamicResource
NewDynamicResource creates a new dynamic resource
func (*DynamicResource) Info ¶
func (r *DynamicResource) Info() ResourceInfo
Info returns the resource metadata
func (*DynamicResource) MimeType ¶
func (r *DynamicResource) MimeType() string
MimeType returns the MIME type
type Error ¶
type Error struct {
// Code is a number that indicates the error type that occurred.
// Standard error codes are defined as constants in this package.
Code int `json:"code"`
// Message provides a short description of the error.
Message string `json:"message"`
// Data contains additional information about the error.
// May be omitted. The value is defined by the server (e.g. detailed error information, nested errors etc.).
Data any `json:"data,omitempty"`
}
Error represents a JSON-RPC 2.0 error object.
type InitializeRequest ¶
type InitializeRequest struct {
// ProtocolVersion specifies the MCP protocol version the client supports.
// Format: "YYYY-MM-DD" (e.g., "2025-06-18").
ProtocolVersion string `json:"protocolVersion"`
// ClientInfo describes the client making the request.
ClientInfo ClientInfo `json:"clientInfo"`
// Capabilities describes the optional features the client supports.
Capabilities Capabilities `json:"capabilities"`
}
InitializeRequest contains the parameters for the initialize method. This is the first request sent by a client to establish a connection.
type InitializeResponse ¶
type InitializeResponse struct {
// ProtocolVersion specifies the MCP protocol version the server supports.
// Must match the version requested by the client.
ProtocolVersion string `json:"protocolVersion"`
// ServerInfo describes the server implementation.
ServerInfo ServerInfo `json:"serverInfo"`
// Capabilities describes the optional features the server supports.
Capabilities Capabilities `json:"capabilities"`
}
InitializeResponse contains the result of a successful initialize request. Sent by the server to complete the initialization handshake.
type MCPServer ¶
type MCPServer interface {
// Start begins serving MCP requests and blocks until the context is cancelled
// or an error occurs.
//
// Start performs the following:
// - Transitions from Uninitialized to Initializing state.
// - Sets up transport layer (stdin/stdout by default).
// - Registers JSON-RPC method handlers.
// - Transitions to Running state after initialization completes.
// - Blocks until ctx.Done() or fatal error.
//
// Start can only be called once. Subsequent calls return an error.
//
// Parameters:
// - ctx: context for server lifetime management and cancellation.
//
// Returns:
// - error: nil on clean shutdown, error if startup or operation fails.
Start(ctx context.Context) error
// Stop gracefully shuts down the server and releases all resources.
//
// Stop performs the following:
// - Transitions to Stopped state.
// - Closes transport connections.
// - Flushes observability events if Emitter is configured.
// - Releases all registered capabilities.
//
// Stop can be called multiple times safely. Subsequent calls are no-ops.
//
// Returns:
// - error: nil on success, error if shutdown fails.
Stop() error
// RegisterTool registers a tool implementation with metadata for MCP clients.
//
// Tools enable LLM clients to perform actions via the server. Each tool must
// have a unique name and provide metadata describing its purpose and parameters.
//
// RegisterTool should be called before Start() to ensure tools are available
// during client initialization. Tools registered after Start() may not be
// visible to already-connected clients.
//
// Parameters:
// - name: unique tool identifier (must match tool.Tool.Name()).
// - tool: tool implementation that executes the tool logic.
// - metadata: descriptive information about the tool and its parameters.
//
// Returns:
// - error: nil on success, error if name conflicts or server is stopped.
RegisterTool(name string, tool tool.Tool, metadata ToolMetadata) error
// RegisterResource is deprecated. Use RegisterStaticResource or RegisterDynamicResource instead.
//
// Deprecated: Use RegisterStaticResource for fixed content or RegisterDynamicResource for computed content.
RegisterResource(uri string, resource Resource) error
// RegisterStaticResource registers a resource with fixed content.
//
// Static resources have content that is fixed at registration time and never changes.
// Use this for cached data, configuration files, or any content that doesn't need
// to be computed on-demand.
//
// RegisterStaticResource should be called before Start() to ensure resources are
// available during client initialization.
//
// Parameters:
// - uri: unique resource identifier (must match pattern ^[a-z][a-z0-9_/]*$).
// - name: human-readable resource name.
// - description: resource description for clients.
// - mimeType: MIME type of the content (e.g., "application/json", "text/plain").
// - content: the resource content as bytes.
//
// Returns:
// - error: nil on success, error if URI conflicts, invalid, or content exceeds size limit.
RegisterStaticResource(uri, name, description, mimeType string, content []byte) error
// RegisterDynamicResource registers a resource with computed content.
//
// Dynamic resources compute content on-demand using a generator function. Use this
// for live metrics, current state, or any content that changes over time.
//
// The generator function is called each time a client reads the resource and should
// respect context cancellation.
//
// RegisterDynamicResource should be called before Start() to ensure resources are
// available during client initialization.
//
// Parameters:
// - uri: unique resource identifier (must match pattern ^[a-z][a-z0-9_/]*$).
// - name: human-readable resource name.
// - description: resource description for clients.
// - mimeType: MIME type of the content (e.g., "application/json", "text/plain").
// - generator: function that computes content on-demand, receives context for cancellation.
//
// Returns:
// - error: nil on success, error if URI conflicts, invalid, or generator is nil.
RegisterDynamicResource(uri, name, description, mimeType string, generator func(context.Context) ([]byte, error)) error
// RegisterPrompt registers a prompt template that clients can invoke.
//
// Prompt templates provide reusable prompts with parameter substitution,
// enabling clients to generate consistent prompts for common tasks.
//
// RegisterPrompt should be called before Start() to ensure prompts are
// available during client initialization.
//
// Parameters:
// - template: prompt template implementation with name and rendering logic.
//
// Returns:
// - error: nil on success, error if name conflicts or server is stopped.
RegisterPrompt(template PromptTemplate) error
}
MCPServer defines the interface for an MCP protocol server implementation.
The server manages the lifecycle of MCP communication, including: - Starting and stopping the server. - Registering tools, resources, and prompt templates. - Handling client initialization and capability negotiation. - Processing JSON-RPC requests.
Implementations must enforce lifecycle state transitions and thread safety.
Example usage:
config := ServerConfig{
Name: "weather-server",
Version: "1.0.0",
Emitter: myEmitter,
}
server := NewServer(config)
// Register capabilities
server.RegisterTool("get_weather", weatherTool, ToolMetadata{
Description: "Get current weather for a location",
Schema: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"location": map[string]interface{}{"type": "string"},
},
"required": []string{"location"},
},
})
// Start server
if err := server.Start(ctx); err != nil {
log.Fatal(err)
}
defer server.Stop()
func NewServer ¶
func NewServer(config ServerConfig) MCPServer
NewServer creates a new MCP server with the given configuration.
The server starts in Uninitialized state and must be started with Start(). All capabilities (tools, resources, prompts) should be registered before calling Start().
Parameters:
- config: server configuration with name, version, and optional emitter.
Returns:
- MCPServer: configured server ready to register capabilities and start.
type Message ¶
Message represents a single message in a rendered prompt. Follows MCP protocol message structure.
type PromptInfo ¶
type PromptInfo struct {
Name string
Description string
Arguments []PromptParameter
}
PromptInfo represents metadata for a registered prompt (returned by List()). Excludes the template string to reduce response size.
type PromptParameter ¶
type PromptParameter struct {
// Name: Parameter name (used in {{name}} placeholders)
// SHOULD match pattern: ^[a-z][a-z0-9_]*$ (recommended)
Name string
// Description: Parameter description (optional)
// Helps LLM understand parameter purpose
Description string
// Required: Whether parameter must be provided during rendering
// If true and parameter not provided, Render() returns error
Required bool
// DefaultValue: Default value if parameter not provided (optional)
// Only used when Required=false
// If empty and parameter not provided, placeholder remains empty
DefaultValue string
}
T079 [P] [US3] Define PromptParameter struct in `graph/mcp/prompt_registry.go`
PromptParameter defines metadata for a template parameter.
Contract: contracts/prompt-registry.md#PromptParameter Data Model: data-model.md#PromptParameter
type PromptRegistry ¶
type PromptRegistry struct {
// contains filtered or unexported fields
}
T080 [P] [US3] Define PromptRegistry struct in `graph/mcp/prompt_registry.go`
PromptRegistry manages prompt templates with thread-safe operations. Supports registration, retrieval, listing, and rendering of prompts.
Thread Safety: Uses sync.RWMutex for concurrent access - Register: Write lock (infrequent, during initialization) - Get, List, Render: Read lock (frequent, during requests)
Contract: contracts/prompt-registry.md#Prompt Registration Data Model: data-model.md#PromptRegistry
func NewPromptRegistry ¶
func NewPromptRegistry() *PromptRegistry
NewPromptRegistry creates a new empty prompt registry.
func (*PromptRegistry) Get ¶
func (r *PromptRegistry) Get(name string) (*PromptTemplate, error)
T082 [US3] Implement PromptRegistry.Get method
Get retrieves a prompt template by name.
Returns: - *PromptTemplate: The template (read-only copy) - error: ErrPromptNotFound if name doesn't exist
Thread-safe: Uses read lock.
func (*PromptRegistry) List ¶
func (r *PromptRegistry) List() []PromptInfo
T083 [US3] Implement PromptRegistry.List method
List returns metadata for all registered prompts. Excludes template string to reduce response size. Results are sorted by name for consistency.
Returns: - []PromptInfo: Array of prompt metadata (may be empty)
Thread-safe: Uses read lock.
func (*PromptRegistry) Register ¶
func (r *PromptRegistry) Register(template PromptTemplate) error
T081 [US3] Implement PromptRegistry.Register method
Register adds a prompt template to the registry with validation.
Validation: - Prompt name MUST match pattern ^[a-z][a-z0-9_]*$ - Prompt name MUST be unique (no duplicates) - Description MUST be non-empty - Template MUST be non-empty - Parameter names MUST match pattern ^[a-z][a-z0-9_]*$ - Parameter names MUST be unique (no duplicates) - All placeholders in template MUST have corresponding parameters
Returns error if validation fails. Thread-safe: Uses write lock.
func (*PromptRegistry) Render ¶
func (r *PromptRegistry) Render(name string, arguments map[string]string) (*RenderedPrompt, error)
T084 [US3] Implement PromptRegistry.Render method (substitute {{param}} placeholders)
Render generates a fully rendered prompt by substituting template placeholders.
Placeholder syntax: {{parameter_name}} or {{ parameter_name }} (whitespace allowed)
Parameter substitution rules: 1. Required parameters MUST be present in arguments 2. Optional parameters use DefaultValue if not provided 3. Extra arguments (not in parameters) are ignored 4. All parameter values MUST be strings
Placeholders are matched using regex to support whitespace variants. Substitution is performed in a single pass using strings.Replacer for efficiency.
Returns: - *RenderedPrompt: Rendered prompt with messages - error: ErrPromptNotFound, ErrMissingParameter, etc.
Thread-safe: Uses read lock.
type PromptTemplate ¶
type PromptTemplate struct {
// Name: Unique prompt identifier
// MUST match pattern: ^[a-z][a-z0-9_]*$ (lowercase, underscores)
// Examples: "start_workflow", "resume_checkpoint", "analyze_results"
Name string
// Description: Human-readable description of prompt purpose
// MUST be non-empty
Description string
// Parameters: Template parameters (optional, can be empty array)
// Defines which placeholders are available in the template
Parameters []PromptParameter
// Template: Template string with {{param}} placeholders
// MUST be non-empty
// Placeholders are substituted during rendering
// Example: "Start workflow '{{workflow_id}}' with input: {{input_data}}"
Template string
}
T078 [P] [US3] Define PromptTemplate struct in `graph/mcp/prompt_registry.go`
PromptTemplate represents a reusable prompt template with parameter substitution. Templates use {{parameter}} placeholder syntax for variable substitution.
Contract: contracts/prompt-registry.md Data Model: data-model.md#PromptTemplate
type RegisteredTool ¶
type RegisteredTool struct {
Tool tool.Tool
Metadata ToolAdapterMetadata
}
RegisteredTool wraps a tool with its metadata.
type RegistryOption ¶
type RegistryOption func(*toolRegistry)
RegistryOption configures the tool registry.
func WithEmitter ¶
func WithEmitter(emitter emit.Emitter) RegistryOption
WithEmitter sets an emitter for observability events.
type RenderedPrompt ¶
RenderedPrompt represents a fully rendered prompt ready for LLM consumption. Returned by Render() after parameter substitution.
type Request ¶
type Request struct {
// JSONRPC specifies the JSON-RPC protocol version. Must be exactly "2.0".
JSONRPC string `json:"jsonrpc"`
// ID is a unique identifier for the request. Used to correlate requests with responses.
// May be a string, number, or null. Omitted for notification requests.
ID any `json:"id,omitempty"`
// Method is the name of the method to be invoked.
Method string `json:"method"`
// Params holds the parameter values to be used during the invocation of the method.
// May be omitted if the method requires no parameters.
Params any `json:"params,omitempty"`
}
Request represents a JSON-RPC 2.0 request message as defined by the MCP specification. All MCP requests follow the JSON-RPC 2.0 protocol structure.
func UnmarshalRequest ¶
UnmarshalRequest parses a JSON-RPC 2.0 request from the given data. Returns ErrCodeParseError if the JSON is invalid.
type Resource ¶
type Resource interface {
// URI returns the resource identifier
URI() string
// MimeType returns the content type
MimeType() string
// Read fetches resource content (may be cached or computed)
Read(ctx context.Context) ([]byte, error)
// Info returns the resource metadata
Info() ResourceInfo
}
Resource is the interface implemented by all resource types
type ResourceContent ¶
type ResourceContent struct {
URI string `json:"uri"`
MimeType string `json:"mimeType"`
Text string `json:"text,omitempty"`
Blob string `json:"blob,omitempty"`
}
ResourceContent represents the content returned by resources/read
func FormatResourceContent ¶
func FormatResourceContent(uri, mimeType string, content []byte) ResourceContent
FormatResourceContent formats resource content for JSON-RPC response
type ResourceInfo ¶
type ResourceInfo struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description"`
MimeType string `json:"mimeType"`
}
ResourceInfo contains metadata about a resource
type ResourceProvider ¶
type ResourceProvider interface {
// RegisterStatic registers a resource with fixed content
RegisterStatic(uri, name, description, mimeType string, content []byte) error
// RegisterDynamic registers a resource with computed content
RegisterDynamic(uri, name, description, mimeType string, generator func(context.Context) ([]byte, error)) error
// Get retrieves a resource by URI
Get(uri string) (Resource, error)
// List returns all resource metadata
List() []ResourceInfo
// Read fetches resource content by URI
Read(ctx context.Context, uri string) ([]byte, error)
}
ResourceProvider manages resource registration and access
func NewResourceProvider ¶
func NewResourceProvider(opts ...ResourceProviderOption) ResourceProvider
NewResourceProvider creates a new resource provider
type ResourceProviderOption ¶
type ResourceProviderOption func(*resourceProvider)
ResourceProviderOption configures a ResourceProvider
func WithMaxResourceSize ¶
func WithMaxResourceSize(maxSize int) ResourceProviderOption
WithMaxResourceSize sets the maximum resource size
func WithMutableResources ¶
func WithMutableResources(allow bool) ResourceProviderOption
WithMutableResources allows resources to be registered after creation
func WithResourceEmitter ¶
func WithResourceEmitter(emitter emit.Emitter) ResourceProviderOption
WithResourceEmitter sets the emitter for observability
type ResourcesListResult ¶
type ResourcesListResult struct {
Resources []ResourceInfo `json:"resources"`
}
ResourcesListResult is the result for resources/list method
type ResourcesReadParams ¶
type ResourcesReadParams struct {
URI string `json:"uri"`
}
ResourcesReadParams are the parameters for resources/read method
type ResourcesReadResult ¶
type ResourcesReadResult struct {
Contents []ResourceContent `json:"contents"`
}
ResourcesReadResult is the result for resources/read method
type Response ¶
type Response struct {
// JSONRPC specifies the JSON-RPC protocol version. Must be exactly "2.0".
JSONRPC string `json:"jsonrpc"`
// ID is the identifier from the corresponding request. Must match the request ID.
ID any `json:"id"`
// Result contains the result of the method invocation if successful.
// Must be omitted if there was an error.
Result any `json:"result,omitempty"`
// Error contains error information if the method invocation failed.
// Must be omitted if the method succeeded.
Error *Error `json:"error,omitempty"`
}
Response represents a JSON-RPC 2.0 response message. Either Result or Error must be present, but not both.
func UnmarshalResponse ¶
UnmarshalResponse parses a JSON-RPC 2.0 response from the given data. Returns ErrCodeParseError if the JSON is invalid.
type ServerConfig ¶
type ServerConfig struct {
// Name is the human-readable server name exposed to clients.
// Example: "langgraph-weather", "database-tools".
Name string
// Version is the semantic version of the server implementation.
// Example: "1.0.0", "2.1.3-beta".
Version string
// Emitter is an optional observability backend for emitting server events.
// If nil, no events are emitted (useful for testing or minimal setups).
Emitter emit.Emitter
}
ServerConfig contains configuration for creating an MCP server instance.
type ServerInfo ¶
type ServerInfo struct {
// Name is the name of the server implementation.
Name string `json:"name"`
// Version is the version of the server implementation.
Version string `json:"version"`
}
ServerInfo describes the server implementation responding to MCP requests. Returned in the initialize response to identify the server.
type StaticResource ¶
type StaticResource struct {
// contains filtered or unexported fields
}
StaticResource represents a resource with fixed content
func NewStaticResource ¶
func NewStaticResource(uri, name, description, mimeType string, content []byte) *StaticResource
NewStaticResource creates a new static resource
func (*StaticResource) Info ¶
func (r *StaticResource) Info() ResourceInfo
Info returns the resource metadata
func (*StaticResource) MimeType ¶
func (r *StaticResource) MimeType() string
MimeType returns the MIME type
type ToolAdapterMetadata ¶
type ToolAdapterMetadata struct {
Name string // Tool name (validated against pattern ^[a-z][a-z0-9_]*$)
Description string // Human-readable description
InputSchema map[string]interface{} // JSON Schema for input validation
}
ToolAdapterMetadata represents metadata for tool registration in the adapter. This is separate from the server's ToolMetadata to follow MCP spec exactly.
type ToolMetadata ¶
type ToolMetadata struct {
// Description provides a human-readable explanation of what the tool does.
Description string `json:"description"`
// Schema defines the input parameters expected by the tool.
// This should be a JSON Schema object describing the tool's input structure.
Schema map[string]interface{} `json:"schema,omitempty"`
}
ToolMetadata contains metadata about a registered tool. This includes description, input schema, and other properties needed for tool discovery and validation.
type ToolRegistry ¶
type ToolRegistry interface {
// Register a LangGraph tool with MCP metadata
Register(tool tool.Tool, metadata ToolAdapterMetadata) error
// Get registered tool by name
Get(name string) (*RegisteredTool, error)
// List all tool metadata
List() []ToolAdapterMetadata
// Invoke tool with validated input
Invoke(ctx context.Context, name string, arguments map[string]interface{}) (*ToolResult, error)
}
ToolRegistry manages tool registration and invocation for MCP.
func NewToolRegistry ¶
func NewToolRegistry(opts ...RegistryOption) ToolRegistry
NewToolRegistry creates a new tool registry instance.
type ToolResult ¶
type ToolResult struct {
Content []ContentBlock
IsError bool
}
ToolResult represents the result of a tool invocation.