-
Notifications
You must be signed in to change notification settings - Fork 36
Add opt-in documentation discovery (llms.txt) to the MCP server #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rohitkumarbhagat
merged 8 commits into
datacommonsorg:main
from
rohitkumarbhagat:llms_txt
Sep 15, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc683a1
docs: update system instructions to include documentation source URL …
rohitkumarbhagat 5e5ebf7
docs: clarify instructions for fetching official documentation versus…
rohitkumarbhagat c25453c
feat: add optional documentation resource
rohitkumarbhagat e9ac953
Merge branch 'main' of github.com:datacommonsorg/agent-toolkit into l…
rohitkumarbhagat f8636ac
feat: allow client overrides for documentation discovery
rohitkumarbhagat a3c45e6
chore: remove DC_ENABLE_DOCUMENTATION_RESOURCE env var from autopush …
rohitkumarbhagat e9bca4d
Simplify optional documentation guidance to a direct URL
rohitkumarbhagat 655da80
Make documentation guidance HTTP opt-in only
rohitkumarbhagat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
1 change: 1 addition & 0 deletions
1
...ages/datacommons-mcp/datacommons_mcp/instructions/doc_instructions_extension.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| For Data Commons API, client library, schema, dataset coverage, concept, or integration questions, fetch https://docs.datacommons.org/llms.txt and use its index to open only the documentation pages relevant to the question. For statistical data queries, use the MCP tools and skills instead. |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Copyright 2026 Google LLC. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """Protocol tests for client-controlled documentation guidance.""" | ||
|
|
||
| import asyncio | ||
| from functools import partial | ||
|
|
||
| import pytest | ||
| from datacommons_mcp.app import DCApp | ||
| from datacommons_mcp.middleware import DOCUMENTATION_HEADER, DocumentationMiddleware | ||
| from fastmcp import Client | ||
| from fastmcp.client.transports import StreamableHttpTransport | ||
| from fastmcp.utilities.tests import run_server_async | ||
| from mcp import McpError | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def documentation_app(monkeypatch, tmp_path, create_test_file): | ||
| create_test_file("server.md", "Custom server instructions.\n") | ||
| create_test_file("doc_instructions_extension.md", "Custom documentation hint.\n") | ||
| monkeypatch.setenv("DC_INSTRUCTIONS_DIR", str(tmp_path)) | ||
| return DCApp | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_documentation_http_opt_in(documentation_app, monkeypatch): | ||
| app = documentation_app() | ||
| server = app.mcp | ||
| original = server.instructions | ||
| monkeypatch.setattr( | ||
| server, "run_http_async", partial(server.run_http_async, stateless_http=True) | ||
| ) | ||
|
|
||
| @server.resource("test://unrelated") | ||
| def unrelated(): | ||
| return "unchanged" | ||
|
|
||
| async with run_server_async(server) as url: | ||
|
|
||
| async def check(header): | ||
| enabled = header is not None and header.lower() == "true" | ||
| headers = {} if header is None else {DOCUMENTATION_HEADER: header} | ||
| async with Client(StreamableHttpTransport(url, headers=headers)) as client: | ||
| result = await client.initialize() | ||
| expected = "Custom server instructions.\n" | ||
| if enabled: | ||
| expected = ( | ||
| "Custom server instructions.\n\nCustom documentation hint.\n" | ||
| ) | ||
| assert result.instructions == expected | ||
| for _ in range(2): | ||
| resources = await client.list_resources() | ||
| assert [str(r.uri) for r in resources] == ["test://unrelated"] | ||
| assert (await client.read_resource("test://unrelated"))[ | ||
| 0 | ||
| ].text == "unchanged" | ||
|
|
||
| await asyncio.gather( | ||
| *(check(value) for value in [None, "true", "false", "TRUE"]) | ||
| ) | ||
| async with Client( | ||
| StreamableHttpTransport(url, headers={DOCUMENTATION_HEADER: "invalid"}), | ||
| auto_initialize=False, | ||
| ) as client: | ||
| with pytest.raises(McpError, match="must be true or false") as error: | ||
| await client.initialize() | ||
| assert error.value.error.code == -32602 | ||
| assert server.instructions == original | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_documentation_without_http_header(documentation_app): | ||
| """Headerless transports receive only the base instructions.""" | ||
| app = documentation_app() | ||
| async with Client(app.mcp) as client: | ||
| result = await client.initialize() | ||
| expected = "Custom server instructions.\n" | ||
| assert result.instructions == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize(("value", "expected"), [(" TRUE ", True), (" false ", False)]) | ||
| def test_documentation_header_whitespace(value, expected, monkeypatch): | ||
| monkeypatch.setattr( | ||
| "datacommons_mcp.middleware.get_http_headers", | ||
| lambda: {DOCUMENTATION_HEADER.lower(): value}, | ||
| ) | ||
| middleware = DocumentationMiddleware( | ||
| base_instructions="base", | ||
| documentation_instructions="base with documentation", | ||
| ) | ||
| assert middleware._enabled() is expected |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.