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 ¶
- type Server
- func (s *Server) HandleMap(ctx context.Context, req mcpgo.CallToolRequest) (*mcpgo.CallToolResult, error)
- func (s *Server) HandleSearch(ctx context.Context, req mcpgo.CallToolRequest) (*mcpgo.CallToolResult, error)
- func (s *Server) Serve(ctx context.Context) error
- func (s *Server) ServeIO(ctx context.Context, in io.Reader, out io.Writer) error
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 ¶
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 ¶
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.