Skip to content

Commit 060427b

Browse files
committed
Add documentation resource endpoints to MCP server
Introduces a FileResource for llms.txt and an async handler to fetch documentation content from the Firefox Source Tree. These additions enable the retrieval and serving of documentation sections to assist LLMs and users.
1 parent 7add600 commit 060427b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

mcp/src/bugbug_mcp/server.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55

66
import functools
77
import os
8+
from pathlib import Path
89
from typing import Annotated
910
from urllib.parse import urlparse
1011

12+
import httpx
1113
from fastmcp import FastMCP
14+
from fastmcp.resources import FileResource
1215
from pydantic import Field
1316

1417
from bugbug import phabricator, utils
@@ -249,6 +252,31 @@ def get_phabricator_revision(revision_id: int) -> str:
249252
return PhabricatorPatch(revision_id=revision_id).to_md()
250253

251254

255+
llms_txt = FileResource(
256+
uri="docs://llms.txt",
257+
path=Path("./static/llms.txt").resolve(),
258+
name="llms.txt for Firefox Source Tree Documentation",
259+
description="This resource provides the knowledge to help with Firefox related workflows and troubleshooting. You must use it to understand questions about Firefox development, architecture, and best practices before trying to search anywhere else. You need to read the relevant sections to get enough context to perform your task.",
260+
mime_type="text/markdown",
261+
)
262+
mcp.add_resource(llms_txt)
263+
264+
265+
@mcp.resource(
266+
uri="docs://{doc_path*}",
267+
name="Content from Documentation",
268+
mime_type="text/markdown",
269+
)
270+
async def handle_doc_view_resource(doc_path: str) -> str:
271+
"""Retrieve the content of a section from Firefox Source Tree Documentation."""
272+
url = f"https://firefox-source-docs.mozilla.org/_sources/{doc_path}.txt"
273+
274+
async with httpx.AsyncClient() as client:
275+
response = await client.get(url)
276+
response.raise_for_status()
277+
return response.text
278+
279+
252280
def main():
253281
phabricator.set_api_key(
254282
get_secret("PHABRICATOR_URL"), get_secret("PHABRICATOR_TOKEN")

0 commit comments

Comments
 (0)