Implement MCP server for GIQL documentation and operator reference#56
Merged
conradbzura merged 6 commits intomainfrom Mar 3, 2026
Merged
Implement MCP server for GIQL documentation and operator reference#56conradbzura merged 6 commits intomainfrom
conradbzura merged 6 commits intomainfrom
Conversation
Add fastmcp as an optional "mcp" dependency and to the dev group. Register giql-mcp console script entry point for the MCP server.
Expose GIQL operator reference, syntax guide, and documentation
through the Model Context Protocol so AI assistants can query
structured information instead of hallucinating GIQL syntax.
Tools: list_operators, explain_operator, get_syntax_reference,
search_docs. Resource: giql://docs/{path} for full doc pages.
Closes #55
Cover clean_rst, find_docs_root, DOC_PATHS validation, list_operators, explain_operator, get_syntax_reference, get_documentation, and search_docs across 7 test classes and 21 test methods.
The MCP server tests require fastmcp, which is only installed via the optional mcp extra. Update pip install to use ".[mcp]" so CI picks up the dependency.
Covers installation, running the server, client configuration, interactive testing with FastMCP Inspector, and a summary of available tools and resources.
027d2b2 to
b35e4aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a Model Context Protocol (MCP) server that exposes GIQL's operator reference, syntax guide, and full documentation as structured tools and resources. Any MCP-compatible client (Claude Desktop, Cursor, VS Code agents) can discover GIQL operators, look up syntax, and search docs on demand — eliminating hallucinated queries from LLMs unfamiliar with the dialect.
Closes #55
Proposed changes
New subpackage
src/giql/mcp/Add
__init__.pyandserver.pyimplementing a FastMCP server with:giql://docs/{path}— serve cleaned RST documentation by pathlist_operators— return all GIQL operators with category, description, and syntaxexplain_operator— return full documentation for a named operatorget_syntax_reference— return the complete syntax quick referencesearch_docs— full-text search across all documentation filesOperator metadata (signatures, parameters, examples, doc-file mappings) is embedded in the server module. RST content is read from the
docs/tree at runtime and cleaned for LLM consumption (directives stripped, cross-references simplified, code blocks converted to fenced markdown).Doc path constants align with the actual repository layout (
dialect/,transpilation/,recipes/).Packaging changes in
pyproject.tomlfastmcpas an optional dependency under anmcpextrafastmcpto the dev dependency groupgiql-mcpconsole entry pointRST cleaning utility
clean_rst()converts Sphinx RST to plain text suitable for LLM context windows: removetoctree/contentsdirectives, convertcode-blockto fenced blocks, simplify cross-references, and collapse excess blank lines.MCP server README
Add
src/giql/mcp/README.mddocumenting installation, running the server, MCP client configuration, interactive testing with FastMCP Inspector, and available tools and resources.Test cases
TestCleanRst.. toctree::directiveclean_rst()is calledTestCleanRst.. code-block:: sqldirectiveclean_rst()is called```sqlblockTestCleanRst:ref:and:doc:cross-referencesclean_rst()is calledTestFindDocsRootGIQL_DOCSenv var set to existing directoryfind_docs_root()is calledTestFindDocsRootGIQL_DOCSset to nonexistent pathfind_docs_root()is calledTestDocPathsDOC_PATHSdict.rstTestDocPathsDOC_PATHSdictdialect,transpilation,recipessubdirectories usedTestDocPathsOPERATORSdictdoc_filevalues are inspecteddialect/TestListOperatorslist_operators()is calledTestListOperatorslist_operators()is calledTestExplainOperatorexplain_operator("INTERSECTS")is calledfull_documentationis populated with section contentTestExplainOperatorexplain_operator("distance")is calledTestExplainOperator"BOGUS"explain_operator()is calledTestExplainOperatorDOCS_ROOTisNoneexplain_operator("MERGE")is calledfull_documentationisNoneTestGetSyntaxReferenceget_syntax_reference()is calledTestGetDocumentationget_documentation("quickstart")is calledTestGetDocumentationget_documentation("nonexistent/page")is calledTestGetDocumentationDOCS_ROOTisNoneget_documentation("quickstart")is calledTestSearchDocssearch_docs("Quickstart")is calledTestSearchDocssearch_docs("xyzzy_nonexistent_term_12345")is calledTestSearchDocsDOCS_ROOTisNonesearch_docs("anything")is calledImplementation plan
fastmcpoptional dependency andgiql-mcpentry point topyproject.tomlsrc/giql/mcp/__init__.pysrc/giql/mcp/server.pywith operator metadata, RST utilities, doc path constants aligned todocs/layout, resource, tools, and entry pointtests/test_mcp_server.pycovering CR-001 through SD-003 (21 tests, 87% server module coverage)src/giql/mcp/README.mdwith installation, configuration, testing, and API reference