MCPCorpusServer#

class scikitplot.corpus.MCPCorpusServer(index, embedding_fn=None, server_name='corpus-search')[source]#

MCP server adapter for corpus search.

Provides a structured interface for building MCP servers that expose corpus search as tools and resources.

Parameters:
indexSimilarityIndex

A built similarity index.

embedding_fnCallable[[str], list[float]] or None, optional

Function to embed query text.

server_namestr, optional

Name of the MCP server.

Parameters:
  • index (Any)

  • embedding_fn (Any)

  • server_name (str)

Notes

User note: Use with any MCP server framework:

from mcp.server import Server

mcp_adapter = MCPCorpusServer(index, embedding_fn)

server = Server("corpus-search")

@server.tool("search")
async def search(query: str, top_k: int = 10):
    return mcp_adapter.handle_search(query, top_k=top_k)

@server.resource("corpus://{doc_id}")
async def get_doc(doc_id: str):
    return mcp_adapter.handle_resource(doc_id)

References

[1]

Model Context Protocol, https://modelcontextprotocol.io/

handle_resource(doc_id)[source]#

Handle an MCP resources/read request.

Returns:
dict[str, Any] or None

MCP resource, or None if not found.

Parameters:

doc_id (str)

Return type:

dict[str, Any] | None

Handle an MCP tools/call request.

Returns:
dict[str, Any]

MCP tool result.

Parameters:
Return type:

dict[str, Any]

list_tools()[source]#

Return MCP tool definitions for this server.

Returns:
list[dict]

Tool schemas compatible with MCP tools/list.

Return type:

list[dict[str, Any]]