mcpkit

package module
v0.1.0 Latest Latest
Warning

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

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

README

hawk-mcpkit

Shared MCP server scaffolding for the hawk ecosystem.

mcpkit wraps mark3labs/mcp-go with the construction, transports, and handler helpers that every hawk-ecosystem library (inspect, sight, ...) would otherwise duplicate. Repos declare their tools and handlers; mcpkit does the rest.

Install

go get github.com/GrayCodeAI/hawk-mcpkit

Usage

package main

import (
	mcpkit "github.com/GrayCodeAI/hawk-mcpkit"
	mcplib "github.com/mark3labs/mcp-go/mcp"
)

func main() {
	s := mcpkit.New("mytool", "0.1.0")

	s.AddTool(
		mcplib.NewTool("greet",
			mcplib.WithDescription("Greets a person by name."),
			mcplib.WithString("name", mcplib.Required(), mcplib.Description("Who to greet")),
		),
		func(ctx context.Context, req mcplib.CallToolRequest) (*mcplib.CallToolResult, error) {
			name := mcpkit.StrArg(req, "name")
			if name == "" {
				return mcplib.NewToolResultError("name is required"), nil
			}
			return mcpkit.JSONResult(map[string]string{"greeting": "hello " + name})
		},
	)

	// stdio transport:
	_ = s.ServeStdio()
	// or streamable HTTP at http://localhost:8080/mcp:
	// _ = s.ServeHTTP(":8080")
}

API

Symbol Purpose
New(name, version) Create a *Server with tool capabilities enabled
(*Server).AddTool(tool, handler) Register a tool and its handler
(*Server).ServeStdio() Serve MCP over stdin/stdout
(*Server).ServeHTTP(addr) Serve MCP over streamable HTTP at /mcp
(*Server).MCP() Escape hatch to the underlying *mcpserver.MCPServer
StrArg(req, key) Extract a string tool argument ("" if absent/mistyped)
JSONResult(v) Marshal v as indented JSON into a text tool result

License

MIT — see LICENSE.

Documentation

Overview

Package mcpkit provides the shared scaffolding used by hawk-ecosystem libraries (inspect, sight, ...) to expose their functionality as MCP servers. It wraps github.com/mark3labs/mcp-go with the ecosystem's standard construction, transports, and small handler helpers so that individual repos only declare their tools and handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONResult

func JSONResult(v any) (*mcplib.CallToolResult, error)

JSONResult marshals v as indented JSON and returns it as a text tool result. It returns a protocol-level error only when marshalling fails.

func StrArg

func StrArg(req mcplib.CallToolRequest, key string) string

StrArg extracts a string argument from a tool call request. It returns "" when the argument is absent or is not a string.

Types

type Server

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

Server wraps an mcp-go MCPServer with the ecosystem's standard transports (stdio and streamable HTTP).

func New

func New(name, version string) *Server

New creates a named MCP server with tool capabilities enabled.

func (*Server) AddTool

func (s *Server) AddTool(tool mcplib.Tool, handler mcpserver.ToolHandlerFunc)

AddTool registers a tool and its handler.

func (*Server) MCP

func (s *Server) MCP() *mcpserver.MCPServer

MCP returns the underlying mcp-go server, as an escape hatch for capabilities mcpkit does not wrap.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(addr string) error

ServeHTTP serves MCP over the streamable HTTP transport at http://<addr>/mcp and blocks until the server stops.

func (*Server) ServeStdio

func (s *Server) ServeStdio() error

ServeStdio serves MCP over stdin/stdout and blocks until the stream is closed or the context that mcp-go derives internally is done.

Jump to

Keyboard shortcuts

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