mcpserver

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(exec GraphQLExecutor, serverName string, version string, toolPrefix string, opts ...Option) (http.Handler, error)

New creates an http.Handler that serves an MCP Streamable HTTP server. It wraps a GraphQL executor and exposes registered tools as MCP tools. A condensed SDL must be supplied via WithCondensedSchema.

Types

type ArgDefinition

type ArgDefinition struct {
	Name        string
	Type        string // "string", "integer", "number", "boolean", "object", "array"
	Description string
	Required    bool
	ItemsType   string   // JSON Schema type for array elements
	EnumValues  []string // Allowed values for enum types
}

ArgDefinition describes a single argument for a tool.

type GraphQLExecutor

type GraphQLExecutor interface {
	Execute(ctx context.Context, query string, variables map[string]any) ([]byte, error)
}

GraphQLExecutor executes GraphQL operations and returns the JSON response.

func NewGQLGenExecutor

func NewGQLGenExecutor(es graphql.ExecutableSchema) GraphQLExecutor

NewGQLGenExecutor returns a GraphQLExecutor backed by a gqlgen ExecutableSchema.

type Option

type Option func(*config)

Option configures the MCP server.

func WithCondensedSchema

func WithCondensedSchema(schema string) Option

WithCondensedSchema returns an Option that provides a condensed SDL schema for the get_schema tool to return instead of the full introspection JSON.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger returns an Option that sets an slog.Logger for MCP-level logging.

func WithMaxQuerySize

func WithMaxQuerySize(bytes int) Option

WithMaxQuerySize returns an Option that sets the maximum allowed query size in bytes.

func WithStateless

func WithStateless(stateless bool) Option

WithStateless returns an Option that controls whether the MCP server runs in stateless mode.

func WithTokenVerifier

func WithTokenVerifier(v TokenVerifier) Option

WithTokenVerifier returns an Option that adds bearer token authentication middleware. Use this for simple deployments where the MCP server manages its own auth. For services that already have HTTP middleware (e.g., JWT validation chains), wrap the handler externally instead — this avoids duplicating auth logic and lets you reuse existing middleware stacks.

func WithTools

func WithTools(tools []ToolDefinition) Option

WithTools returns an Option that registers additional tool definitions.

type TokenVerifier

type TokenVerifier func(ctx context.Context, token string) (context.Context, error)

TokenVerifier validates a bearer token and returns an enriched context.

type ToolDefinition

type ToolDefinition struct {
	Name        string
	Description string
	Args        []ArgDefinition
	Query       string
	Annotations *mcp.ToolAnnotations
}

ToolDefinition describes an MCP tool backed by a GraphQL query.

Jump to

Keyboard shortcuts

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