agentsmcp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 4 Imported by: 0

README

mcp

Expose a whilesmartgo/agents tool set over the Model Context Protocol, built on the official MCP Go SDK.

The same tools your assistant calls become an MCP server, so any MCP client (an IDE, a desktop app, another agent) can drive them too. One tool set, two front doors.

Install

go get github.com/whilesmartgo/mcp

Quickstart

package main

import (
	"context"

	"github.com/modelcontextprotocol/go-sdk/mcp"
	"github.com/whilesmartgo/agents"
	agentsmcp "github.com/whilesmartgo/mcp"
)

func main() {
	reg := agents.NewRegistry(/* your agents.Tool values */)
	server := agentsmcp.NewServer("my-app", "v1.0.0", reg)

	// Serve over any MCP transport; stdio is the common one for local clients.
	_ = server.Run(context.Background(), &mcp.StdioTransport{})
}

AddRegistry(server, reg) adds the same tools to a server you already built, for hosts that also carry tools from other sources.

Serving over HTTP

StreamableHTTPHandler returns a stateless http.Handler for MCP's streamable-HTTP transport, so you can mount the tool set on a web server without importing the underlying SDK. The registry is chosen per request, which lets you authenticate the caller and hand back a tool set scoped to their permissions.

handler := agentsmcp.StreamableHTTPHandler("my-app", "v1.0.0", func(r *http.Request) *agents.Registry {
	actor := authenticate(r) // your auth
	if actor == nil {
		return nil // serves 400
	}
	return registryFor(actor)
})
http.Handle("/mcp", handler)

Authorization

The bridge adds no auth of its own. A tool that returns an error yields an MCP error result (IsError) rather than a protocol error, so the caller sees the failure and can adapt. Gate access inside each agents.Tool handler, or with the agents package's Runner.Authorize hook before a tool reaches the registry.

Status

v0, one-directional: it serves an agents.Registry as an MCP server. Consuming external MCP servers as agent tools is not here yet.

License

MIT.

Documentation

Overview

Package agentsmcp bridges a whilesmartgo/agents tool set to the Model Context Protocol, using the official MCP Go SDK for the wire protocol.

The bridge is one-directional in v0: it exposes an agents.Registry as an MCP server, so an MCP client can call the same tools an assistant would. Each MCP tool call runs the corresponding agents.Tool handler. A tool that returns an error yields an error result (IsError) rather than a protocol error, so a model on the other end can see the failure and adapt.

reg := agents.NewRegistry(tool1, tool2)
server := agentsmcp.NewServer("my-app", "v1.0.0", reg)
// serve over any MCP transport, e.g. stdio:
_ = server.Run(ctx, &mcp.StdioTransport{})

To serve over HTTP without touching the underlying SDK, use StreamableHTTPHandler, which picks the registry per request so the tool set can be scoped to the authenticated caller.

The consumer supplies authorization inside each agents.Tool handler (or via the Runner in the agents package); this bridge adds no auth of its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddRegistry

func AddRegistry(server *mcp.Server, reg *agents.Registry)

AddRegistry adds every tool in reg to an existing MCP server. Use it when the server also carries tools from other sources.

func NewServer

func NewServer(name, version string, reg *agents.Registry) *mcp.Server

NewServer builds an MCP server that exposes every tool in reg. name and version identify the server to MCP clients.

func StreamableHTTPHandler added in v0.2.0

func StreamableHTTPHandler(name, version string, getReg func(*http.Request) *agents.Registry) http.Handler

StreamableHTTPHandler serves a tool set over MCP's streamable-HTTP transport. name and version identify the server to clients.

getReg supplies the registry for each request, so a host can authenticate the request and hand back a caller-scoped tool set; returning nil serves 400. The handler is stateless: every call is served with the registry for that request, which is what request-scoped authorization needs. Wrapping the SDK here keeps the official MCP SDK out of consumer imports.

Types

This section is empty.

Jump to

Keyboard shortcuts

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