mcp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package mcp exposes codamigo's search capability as an MCP (Model Context Protocol) stdio server.

Server is constructed with a *query.Querier and optional *indexer.Indexer and watcher.Watcher. Server.Serve runs the MCP stdio loop until the context is cancelled. The server exposes a single "search" tool with query, limit, and refresh_index parameters. When no Indexer is provided, refresh_index=true is silently ignored.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is the MCP stdio server for codamigo.

func NewServer

func NewServer(q *query.Querier, idx *indexer.Indexer, w watcher.Watcher, nonCodeLangs []string) *Server

NewServer constructs the MCP server. All dependencies are optional (may be nil); the server degrades gracefully. When idx is non-nil, a search request with refresh_index=true triggers a full re-index before querying. When w is non-nil, changed files are re-indexed continuously in the background. nonCodeLangs configures which languages are excluded when the get_map code_only option is true.

func NewServerWithIndexer

func NewServerWithIndexer(q *query.Querier, idx indexerIface, w watcher.Watcher, nonCodeLangs []string) *Server

NewServerWithIndexer is like NewServer but accepts any value that satisfies [indexerIface]. This is useful in tests where a lightweight mock replaces the real *indexer.Indexer.

func (*Server) HandleMap

func (s *Server) HandleMap(ctx context.Context, req mcpgo.CallToolRequest) (*mcpgo.CallToolResult, error)

HandleMap is the ToolHandlerFunc for the get_map tool. Exported to allow direct testing without the MCP stdio transport.

func (*Server) HandleSearch

func (s *Server) HandleSearch(ctx context.Context, req mcpgo.CallToolRequest) (*mcpgo.CallToolResult, error)

HandleSearch is the ToolHandlerFunc for the search tool. Exported to allow direct testing without the MCP stdio transport.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve runs the MCP stdio loop over os.Stdin and os.Stdout until ctx is cancelled. See ServeIO for control over the transport streams.

func (*Server) ServeIO

func (s *Server) ServeIO(ctx context.Context, in io.Reader, out io.Writer) error

ServeIO runs the MCP stdio loop over the provided streams until ctx is cancelled. It performs an initial full index (if indexer is non-nil), launches a background watcher goroutine (if both watcher and indexer are non-nil), and then blocks on the MCP stdio protocol loop. All goroutines are joined before ServeIO returns.

Jump to

Keyboard shortcuts

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