server

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package server wires a parsed OpenAPI document into a running MCP server: every tool definition gets a handler that proxies the call to the upstream API and formats the response back into an MCP result.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) *sdk.Server

New builds an MCP server exposing every tool in cfg.Defs.

func ResolveBase

func ResolveBase(doc *openapi.Document, override, specURL string) (string, error)

ResolveBase determines the upstream API root to send requests to. An explicit override always wins. Otherwise the first server URL in the spec is used: absolute URLs as-is, relative URLs resolved against the URL the spec was fetched from. A templated server URL or an unresolvable relative URL is an error that asks the operator for --base.

func RunHTTP

func RunHTTP(ctx context.Context, srv *sdk.Server, addr, infoText string) error

RunHTTP serves the MCP server over the streamable-HTTP transport. The protocol endpoint is mounted at /mcp; any other path returns infoText as plain text, so a human who opens the root URL in a browser gets an explanation instead of a protocol error. The same server instance is shared across sessions. It blocks until ctx is cancelled or the listener fails.

func RunStdio

func RunStdio(ctx context.Context, srv *sdk.Server) error

RunStdio serves the MCP server over stdio, the transport MCP clients use when they spawn a server as a subprocess. It blocks until the client disconnects or ctx is cancelled.

Types

type Config

type Config struct {
	Doc     *openapi.Document
	Defs    []tool.Def
	BaseURL string            // resolved upstream API root
	Headers map[string]string // injected on every upstream request (e.g. auth)
	Timeout time.Duration     // per-request upstream timeout
	Version string            // mcpify version, reported to clients
}

Config describes one mcpify server instance.

Jump to

Keyboard shortcuts

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