Spaces:
Running
Running
Tom Poulenard commited on
Commit ·
fbaf5ce
1
Parent(s): cf1bccc
Hide graph tool and polish MCP landing page.
Browse filesKeep retrieve_graphs unregistered until the OWID index is validated, move homepage HTML/CSS into mcp_server/homepage, and document public no-auth access in the README.
- README.md +11 -1
- app.py +0 -1
- mcp_app.py +19 -203
- mcp_server/homepage/__init__.py +15 -0
- mcp_server/homepage/index.html +100 -0
- mcp_server/homepage/style.css +217 -0
- mcp_server/server.py +5 -4
- mcp_server/tests/test_server.py +6 -52
README.md
CHANGED
|
@@ -20,7 +20,17 @@ HTTP) exposing retrieval tools over the ClimateQ&A indexes.
|
|
| 20 |
| Tool | Input | Output | Notes |
|
| 21 |
| --- | --- | --- | --- |
|
| 22 |
| `retrieve_data_mcp` | `query: str` | `{"documents": [...], "images": [...]}` | IPCC / IPBES / IPOS document chunks and figures. **Backward-compatible** wire contract. |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
## Run locally
|
| 26 |
|
|
|
|
| 20 |
| Tool | Input | Output | Notes |
|
| 21 |
| --- | --- | --- | --- |
|
| 22 |
| `retrieve_data_mcp` | `query: str` | `{"documents": [...], "images": [...]}` | IPCC / IPBES / IPOS document chunks and figures. **Backward-compatible** wire contract. |
|
| 23 |
+
|
| 24 |
+
> **Coming soon:** `retrieve_graphs` — OWID quantitative charts retrieval.
|
| 25 |
+
> The implementation is ready (see `mcp_server/tools/retriever/retrieve_graphs/`),
|
| 26 |
+
> just not exposed yet while the OWID index is being validated. Uncomment the
|
| 27 |
+
> import in `mcp_server/server.py` to enable it.
|
| 28 |
+
|
| 29 |
+
## Authentication
|
| 30 |
+
|
| 31 |
+
This server is **intentionally public** — no API key or auth token is required.
|
| 32 |
+
It is designed to be freely accessible so that any MCP-compatible client
|
| 33 |
+
(Claude, ChatGPT, Cursor, custom agents, etc.) can connect without friction.
|
| 34 |
|
| 35 |
## Run locally
|
| 36 |
|
app.py
CHANGED
|
@@ -12,7 +12,6 @@ from climateqa.engine.reranker import get_reranker
|
|
| 12 |
from climateqa.engine.graph import make_graph_agent, make_graph_agent_poc
|
| 13 |
from climateqa.engine.chains.retrieve_papers import find_papers
|
| 14 |
from climateqa.chat import start_chat, chat_stream, finish_chat
|
| 15 |
-
from mcp_service import make_retrieve_data_mcp, make_retrieve_graphs_mcp
|
| 16 |
|
| 17 |
from front.tabs import create_config_modal, cqa_tab, create_about_tab
|
| 18 |
from front.tabs import MainTabPanel, ConfigPanel
|
|
|
|
| 12 |
from climateqa.engine.graph import make_graph_agent, make_graph_agent_poc
|
| 13 |
from climateqa.engine.chains.retrieve_papers import find_papers
|
| 14 |
from climateqa.chat import start_chat, chat_stream, finish_chat
|
|
|
|
| 15 |
|
| 16 |
from front.tabs import create_config_modal, cqa_tab, create_about_tab
|
| 17 |
from front.tabs import MainTabPanel, ConfigPanel
|
mcp_app.py
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import logging
|
|
@@ -15,215 +25,21 @@ from starlette.applications import Starlette
|
|
| 15 |
from starlette.requests import Request
|
| 16 |
from starlette.responses import HTMLResponse
|
| 17 |
from starlette.routing import Mount, Route
|
|
|
|
| 18 |
|
| 19 |
from mcp_server import mcp
|
|
|
|
| 20 |
from mcp_server.settings import settings
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
def _get_mcp_endpoint() -> str:
|
| 26 |
-
return os.getenv("MCP_PUBLIC_URL", f"http://localhost:{settings.port}/mcp")
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# ---------------------------------------------------------------------------
|
| 30 |
-
# Landing page (static HTML served at /)
|
| 31 |
-
# ---------------------------------------------------------------------------
|
| 32 |
-
|
| 33 |
-
def _render_landing(mcp_endpoint: str) -> str:
|
| 34 |
-
return f"""<!DOCTYPE html>
|
| 35 |
-
<html lang="en">
|
| 36 |
-
<head>
|
| 37 |
-
<meta charset="UTF-8">
|
| 38 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 39 |
-
<title>ClimateQ&A MCP Server</title>
|
| 40 |
-
<style>
|
| 41 |
-
:root {{
|
| 42 |
-
color-scheme: light dark;
|
| 43 |
-
--bg: #f8fafc;
|
| 44 |
-
--card: #ffffff;
|
| 45 |
-
--text: #1e293b;
|
| 46 |
-
--muted: #64748b;
|
| 47 |
-
--border: #e2e8f0;
|
| 48 |
-
--accent: #2563eb;
|
| 49 |
-
--accent-light: #eff6ff;
|
| 50 |
-
}}
|
| 51 |
-
@media (prefers-color-scheme: dark) {{
|
| 52 |
-
:root {{
|
| 53 |
-
--bg: #0f172a;
|
| 54 |
-
--card: #1e293b;
|
| 55 |
-
--text: #f1f5f9;
|
| 56 |
-
--muted: #94a3b8;
|
| 57 |
-
--border: #334155;
|
| 58 |
-
--accent: #60a5fa;
|
| 59 |
-
--accent-light: #1e3a5f;
|
| 60 |
-
}}
|
| 61 |
-
}}
|
| 62 |
-
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
| 63 |
-
body {{
|
| 64 |
-
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 65 |
-
background: var(--bg);
|
| 66 |
-
color: var(--text);
|
| 67 |
-
line-height: 1.6;
|
| 68 |
-
padding: 2rem 1rem;
|
| 69 |
-
}}
|
| 70 |
-
.container {{ max-width: 800px; margin: 0 auto; }}
|
| 71 |
-
h1 {{ font-size: 2rem; margin-bottom: 0.5rem; }}
|
| 72 |
-
h2 {{ font-size: 1.3rem; margin: 2rem 0 0.75rem; color: var(--accent); }}
|
| 73 |
-
h3 {{ font-size: 1.05rem; margin: 1.5rem 0 0.5rem; }}
|
| 74 |
-
p, li {{ color: var(--muted); margin-bottom: 0.5rem; }}
|
| 75 |
-
.subtitle {{ font-size: 1.1rem; color: var(--muted); margin-bottom: 2rem; }}
|
| 76 |
-
.endpoint {{
|
| 77 |
-
background: var(--accent-light);
|
| 78 |
-
border: 1px solid var(--accent);
|
| 79 |
-
border-radius: 8px;
|
| 80 |
-
padding: 1rem 1.25rem;
|
| 81 |
-
margin: 1.5rem 0;
|
| 82 |
-
font-family: 'JetBrains Mono', monospace;
|
| 83 |
-
font-size: 0.95rem;
|
| 84 |
-
word-break: break-all;
|
| 85 |
-
}}
|
| 86 |
-
.card {{
|
| 87 |
-
background: var(--card);
|
| 88 |
-
border: 1px solid var(--border);
|
| 89 |
-
border-radius: 8px;
|
| 90 |
-
padding: 1.5rem;
|
| 91 |
-
margin: 1rem 0;
|
| 92 |
-
}}
|
| 93 |
-
code {{
|
| 94 |
-
background: var(--accent-light);
|
| 95 |
-
padding: 0.15em 0.4em;
|
| 96 |
-
border-radius: 4px;
|
| 97 |
-
font-size: 0.9em;
|
| 98 |
-
}}
|
| 99 |
-
pre {{
|
| 100 |
-
background: var(--card);
|
| 101 |
-
border: 1px solid var(--border);
|
| 102 |
-
border-radius: 8px;
|
| 103 |
-
padding: 1rem;
|
| 104 |
-
overflow-x: auto;
|
| 105 |
-
font-size: 0.85rem;
|
| 106 |
-
margin: 0.75rem 0;
|
| 107 |
-
}}
|
| 108 |
-
table {{ width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; }}
|
| 109 |
-
th, td {{ text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }}
|
| 110 |
-
th {{ font-weight: 600; color: var(--text); }}
|
| 111 |
-
.badge {{
|
| 112 |
-
display: inline-block;
|
| 113 |
-
background: var(--accent);
|
| 114 |
-
color: white;
|
| 115 |
-
padding: 0.2em 0.6em;
|
| 116 |
-
border-radius: 4px;
|
| 117 |
-
font-size: 0.75rem;
|
| 118 |
-
font-weight: 600;
|
| 119 |
-
vertical-align: middle;
|
| 120 |
-
}}
|
| 121 |
-
footer {{ margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }}
|
| 122 |
-
a {{ color: var(--accent); text-decoration: none; }}
|
| 123 |
-
a:hover {{ text-decoration: underline; }}
|
| 124 |
-
</style>
|
| 125 |
-
</head>
|
| 126 |
-
<body>
|
| 127 |
-
<div class="container">
|
| 128 |
-
|
| 129 |
-
<h1>🌎 ClimateQ&A — MCP Server</h1>
|
| 130 |
-
<p class="subtitle">
|
| 131 |
-
Give any AI assistant access to IPCC, IPBES, IPOS scientific reports
|
| 132 |
-
and Our World In Data graphs via the
|
| 133 |
-
<a href="https://modelcontextprotocol.io">Model Context Protocol</a>.
|
| 134 |
-
</p>
|
| 135 |
-
|
| 136 |
-
<div class="endpoint">
|
| 137 |
-
<strong>Endpoint:</strong> {mcp_endpoint}<br>
|
| 138 |
-
<strong>Transport:</strong> Streamable HTTP <span class="badge">MCP 2025-03-26</span>
|
| 139 |
-
</div>
|
| 140 |
-
|
| 141 |
-
<h2>Available Tools</h2>
|
| 142 |
-
<table>
|
| 143 |
-
<tr><th>Tool</th><th>Input</th><th>Description</th></tr>
|
| 144 |
-
<tr>
|
| 145 |
-
<td><code>retrieve_data_mcp</code></td>
|
| 146 |
-
<td><code>query</code> (string)</td>
|
| 147 |
-
<td>IPCC / IPBES / IPOS document chunks and figures</td>
|
| 148 |
-
</tr>
|
| 149 |
-
<tr>
|
| 150 |
-
<td><code>retrieve_graphs</code></td>
|
| 151 |
-
<td><code>query</code> (string)</td>
|
| 152 |
-
<td>OWID quantitative charts with similarity scores and source URLs</td>
|
| 153 |
-
</tr>
|
| 154 |
-
</table>
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
<div class="card">
|
| 159 |
-
<h3>Claude Desktop / Claude Code</h3>
|
| 160 |
-
<pre>{{
|
| 161 |
-
"mcpServers": {{
|
| 162 |
-
"climateqa": {{
|
| 163 |
-
"url": "{mcp_endpoint}"
|
| 164 |
-
}}
|
| 165 |
-
}}
|
| 166 |
-
}}</pre>
|
| 167 |
-
</div>
|
| 168 |
-
|
| 169 |
-
<div class="card">
|
| 170 |
-
<h3>ChatGPT</h3>
|
| 171 |
-
<p>In Settings → MCP connections, add:<br>
|
| 172 |
-
<strong>URL:</strong> <code>{mcp_endpoint}</code></p>
|
| 173 |
-
</div>
|
| 174 |
-
|
| 175 |
-
<div class="card">
|
| 176 |
-
<h3>Cursor IDE</h3>
|
| 177 |
-
<p>Add to <code>.cursor/mcp.json</code>:</p>
|
| 178 |
-
<pre>{{
|
| 179 |
-
"mcpServers": {{
|
| 180 |
-
"climateqa": {{
|
| 181 |
-
"url": "{mcp_endpoint}"
|
| 182 |
-
}}
|
| 183 |
-
}}
|
| 184 |
-
}}</pre>
|
| 185 |
-
</div>
|
| 186 |
-
|
| 187 |
-
<div class="card">
|
| 188 |
-
<h3>LeChat (Mistral)</h3>
|
| 189 |
-
<p>In agent settings, add an MCP tool source:<br>
|
| 190 |
-
<strong>URL:</strong> <code>{mcp_endpoint}</code></p>
|
| 191 |
-
</div>
|
| 192 |
-
|
| 193 |
-
<div class="card">
|
| 194 |
-
<h3>Any MCP-compatible client</h3>
|
| 195 |
-
<p>Connect via <strong>Streamable HTTP</strong> to the endpoint above. No API key required.</p>
|
| 196 |
-
</div>
|
| 197 |
-
|
| 198 |
-
<h2>Example Queries</h2>
|
| 199 |
-
<ul>
|
| 200 |
-
<li><em>"What are the main drivers of sea level rise?"</em></li>
|
| 201 |
-
<li><em>"How has global temperature changed since 1850?"</em></li>
|
| 202 |
-
<li><em>"What is the impact of deforestation on biodiversity?"</em></li>
|
| 203 |
-
<li><em>"Show me CO2 emissions per capita trends"</em></li>
|
| 204 |
-
</ul>
|
| 205 |
-
|
| 206 |
-
<footer>
|
| 207 |
-
<p>
|
| 208 |
-
<strong>ClimateQ&A - MCP</strong>,
|
| 209 |
-
Powered by <a href="https://gofastmcp.com">FastMCP {_FASTMCP_VERSION}</a>
|
| 210 |
-
</p>
|
| 211 |
-
<p>Free and open source</p>
|
| 212 |
-
</footer>
|
| 213 |
-
|
| 214 |
-
</div>
|
| 215 |
-
</body>
|
| 216 |
-
</html>
|
| 217 |
-
"""
|
| 218 |
|
| 219 |
|
| 220 |
async def _index(request: Request) -> HTMLResponse:
|
| 221 |
-
return HTMLResponse(
|
| 222 |
-
|
| 223 |
|
| 224 |
-
# ---------------------------------------------------------------------------
|
| 225 |
-
# Combined app: landing page at / + FastMCP at /mcp on a single port
|
| 226 |
-
# ---------------------------------------------------------------------------
|
| 227 |
|
| 228 |
def build_app() -> Starlette:
|
| 229 |
"""Build the combined Starlette application.
|
|
@@ -231,20 +47,20 @@ def build_app() -> Starlette:
|
|
| 231 |
Route resolution order:
|
| 232 |
1. Exact match ``/`` → landing page
|
| 233 |
2. Catch-all ``Mount("/")`` → FastMCP streamable-HTTP (handles /mcp)
|
| 234 |
-
|
| 235 |
The MCP app's lifespan is hoisted to the parent so the streamable-HTTP
|
| 236 |
session manager initialises correctly.
|
| 237 |
"""
|
| 238 |
mcp_app = mcp.http_app(path="/mcp", transport="streamable-http")
|
| 239 |
|
| 240 |
-
|
| 241 |
routes=[
|
| 242 |
Route("/", _index, methods=["GET"]),
|
|
|
|
| 243 |
Mount("/", app=mcp_app),
|
| 244 |
],
|
| 245 |
lifespan=mcp_app.router.lifespan_context,
|
| 246 |
)
|
| 247 |
-
return app
|
| 248 |
|
| 249 |
|
| 250 |
app = build_app()
|
|
|
|
| 1 |
+
"""ClimateQA MCP Server + Landing Page.
|
| 2 |
+
|
| 3 |
+
Single-process, single-port deployment:
|
| 4 |
+
- ``/`` → HTML landing page (docs, integration guides, tool reference)
|
| 5 |
+
- ``/mcp`` → FastMCP streamable-HTTP endpoint
|
| 6 |
+
|
| 7 |
+
Run:
|
| 8 |
+
python mcp_app.py
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
from __future__ import annotations
|
| 12 |
|
| 13 |
import logging
|
|
|
|
| 25 |
from starlette.requests import Request
|
| 26 |
from starlette.responses import HTMLResponse
|
| 27 |
from starlette.routing import Mount, Route
|
| 28 |
+
from starlette.staticfiles import StaticFiles
|
| 29 |
|
| 30 |
from mcp_server import mcp
|
| 31 |
+
from mcp_server.homepage import render_landing
|
| 32 |
from mcp_server.settings import settings
|
| 33 |
|
| 34 |
+
_HOMEPAGE_DIR = str(__import__("pathlib").Path(__file__).parent / "mcp_server" / "homepage")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
_FASTMCP_VERSION = _pkg_version("fastmcp")
|
| 37 |
+
_MCP_ENDPOINT = os.getenv("MCP_PUBLIC_URL", f"http://localhost:{settings.port}/mcp")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
async def _index(request: Request) -> HTMLResponse:
|
| 41 |
+
return HTMLResponse(render_landing(_MCP_ENDPOINT, _FASTMCP_VERSION))
|
|
|
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def build_app() -> Starlette:
|
| 45 |
"""Build the combined Starlette application.
|
|
|
|
| 47 |
Route resolution order:
|
| 48 |
1. Exact match ``/`` → landing page
|
| 49 |
2. Catch-all ``Mount("/")`` → FastMCP streamable-HTTP (handles /mcp)
|
| 50 |
+
|
| 51 |
The MCP app's lifespan is hoisted to the parent so the streamable-HTTP
|
| 52 |
session manager initialises correctly.
|
| 53 |
"""
|
| 54 |
mcp_app = mcp.http_app(path="/mcp", transport="streamable-http")
|
| 55 |
|
| 56 |
+
return Starlette(
|
| 57 |
routes=[
|
| 58 |
Route("/", _index, methods=["GET"]),
|
| 59 |
+
Mount("/static", app=StaticFiles(directory=_HOMEPAGE_DIR), name="static"),
|
| 60 |
Mount("/", app=mcp_app),
|
| 61 |
],
|
| 62 |
lifespan=mcp_app.router.lifespan_context,
|
| 63 |
)
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
app = build_app()
|
mcp_server/homepage/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Landing page for the ClimateQA MCP server (HF Spaces homepage)."""
|
| 2 |
+
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
_TEMPLATE_PATH = Path(__file__).parent / "index.html"
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def render_landing(mcp_endpoint: str, fastmcp_version: str) -> str:
|
| 9 |
+
"""Render the landing page HTML with the given endpoint URL injected."""
|
| 10 |
+
template = _TEMPLATE_PATH.read_text(encoding="utf-8")
|
| 11 |
+
return (
|
| 12 |
+
template
|
| 13 |
+
.replace("{{MCP_ENDPOINT}}", mcp_endpoint)
|
| 14 |
+
.replace("{{FASTMCP_VERSION}}", fastmcp_version)
|
| 15 |
+
)
|
mcp_server/homepage/index.html
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>ClimateQ&A MCP Server</title>
|
| 7 |
+
<link rel="stylesheet" href="/static/style.css">
|
| 8 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 9 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<div class="container">
|
| 14 |
+
|
| 15 |
+
<div class="header">
|
| 16 |
+
<h1>🌎 ClimateQ&A — MCP Server</h1>
|
| 17 |
+
<p class="subtitle">
|
| 18 |
+
Give any AI assistant access to IPCC, IPBES, IPOS scientific reports
|
| 19 |
+
and Our World In Data graphs via the
|
| 20 |
+
<a href="https://modelcontextprotocol.io">Model Context Protocol</a>.
|
| 21 |
+
</p>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
<div class="endpoint">
|
| 25 |
+
<strong>Endpoint:</strong> {{MCP_ENDPOINT}}<br>
|
| 26 |
+
<strong>Transport:</strong> Streamable HTTP <span class="badge">MCP 2025-03-26</span>
|
| 27 |
+
</div>
|
| 28 |
+
|
| 29 |
+
<h2>Available Tools</h2>
|
| 30 |
+
<table>
|
| 31 |
+
<tr><th>Tool</th><th>Input</th><th>Description</th></tr>
|
| 32 |
+
<tr>
|
| 33 |
+
<td><code>retrieve_data_mcp</code></td>
|
| 34 |
+
<td><code>query</code> (string)</td>
|
| 35 |
+
<td>IPCC / IPBES / IPOS document chunks and figures</td>
|
| 36 |
+
</tr>
|
| 37 |
+
</table>
|
| 38 |
+
<p><em>Coming soon:</em> <code>retrieve_graphs</code> — OWID quantitative charts.</p>
|
| 39 |
+
|
| 40 |
+
<h2>Connect Your AI Assistant</h2>
|
| 41 |
+
|
| 42 |
+
<div class="card">
|
| 43 |
+
<h3>Claude Desktop / Claude Code</h3>
|
| 44 |
+
<pre>{
|
| 45 |
+
"mcpServers": {
|
| 46 |
+
"climateqa": {
|
| 47 |
+
"url": "{{MCP_ENDPOINT}}"
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
}</pre>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<div class="card">
|
| 54 |
+
<h3>ChatGPT</h3>
|
| 55 |
+
<p>In Settings → MCP connections, add:<br>
|
| 56 |
+
<strong>URL:</strong> <code>{{MCP_ENDPOINT}}</code></p>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
<div class="card">
|
| 60 |
+
<h3>Cursor IDE</h3>
|
| 61 |
+
<p>Add to <code>.cursor/mcp.json</code>:</p>
|
| 62 |
+
<pre>{
|
| 63 |
+
"mcpServers": {
|
| 64 |
+
"climateqa": {
|
| 65 |
+
"url": "{{MCP_ENDPOINT}}"
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}</pre>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
<div class="card">
|
| 72 |
+
<h3>LeChat (Mistral)</h3>
|
| 73 |
+
<p>In agent settings, add an MCP tool source:<br>
|
| 74 |
+
<strong>URL:</strong> <code>{{MCP_ENDPOINT}}</code></p>
|
| 75 |
+
</div>
|
| 76 |
+
|
| 77 |
+
<div class="card">
|
| 78 |
+
<h3>Any MCP-compatible client</h3>
|
| 79 |
+
<p>Connect via <strong>Streamable HTTP</strong> to the endpoint above. No API key required.</p>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<h2>Example Queries</h2>
|
| 83 |
+
<ul>
|
| 84 |
+
<li><em>"What are the main drivers of sea level rise?"</em></li>
|
| 85 |
+
<li><em>"How has global temperature changed since 1850?"</em></li>
|
| 86 |
+
<li><em>"What is the impact of deforestation on biodiversity?"</em></li>
|
| 87 |
+
<li><em>"Show me CO2 emissions per capita trends"</em></li>
|
| 88 |
+
</ul>
|
| 89 |
+
|
| 90 |
+
<footer>
|
| 91 |
+
<p>
|
| 92 |
+
<strong>ClimateQ&A - MCP</strong>,
|
| 93 |
+
Powered by <a href="https://gofastmcp.com">FastMCP {{FASTMCP_VERSION}}</a>
|
| 94 |
+
</p>
|
| 95 |
+
<p>Free and open source</p>
|
| 96 |
+
</footer>
|
| 97 |
+
|
| 98 |
+
</div>
|
| 99 |
+
</body>
|
| 100 |
+
</html>
|
mcp_server/homepage/style.css
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
color-scheme: light dark;
|
| 3 |
+
--bg: #f8fafc;
|
| 4 |
+
--card: #ffffff;
|
| 5 |
+
--text: #1e293b;
|
| 6 |
+
--muted: #64748b;
|
| 7 |
+
--border: #e2e8f0;
|
| 8 |
+
--accent: #2563eb;
|
| 9 |
+
--accent-light: #eff6ff;
|
| 10 |
+
--accent-gradient: linear-gradient(135deg, #2563eb 0%, #0ea5e9 100%);
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
@media (prefers-color-scheme: dark) {
|
| 14 |
+
:root {
|
| 15 |
+
--bg: #0f172a;
|
| 16 |
+
--card: #1e293b;
|
| 17 |
+
--text: #f1f5f9;
|
| 18 |
+
--muted: #94a3b8;
|
| 19 |
+
--border: #334155;
|
| 20 |
+
--accent: #60a5fa;
|
| 21 |
+
--accent-light: #1e3a5f;
|
| 22 |
+
--accent-gradient: linear-gradient(135deg, #60a5fa 0%, #38bdf8 100%);
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
* {
|
| 27 |
+
margin: 0;
|
| 28 |
+
padding: 0;
|
| 29 |
+
box-sizing: border-box;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
body {
|
| 33 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
| 34 |
+
background: var(--bg);
|
| 35 |
+
color: var(--text);
|
| 36 |
+
line-height: 1.7;
|
| 37 |
+
padding: 3rem 1.5rem;
|
| 38 |
+
-webkit-font-smoothing: antialiased;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.container {
|
| 42 |
+
max-width: 780px;
|
| 43 |
+
margin: 0 auto;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
/* Header */
|
| 47 |
+
.header {
|
| 48 |
+
text-align: center;
|
| 49 |
+
margin-bottom: 2.5rem;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
h1 {
|
| 53 |
+
font-size: 2.25rem;
|
| 54 |
+
font-weight: 700;
|
| 55 |
+
margin-bottom: 0.75rem;
|
| 56 |
+
letter-spacing: -0.025em;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.subtitle {
|
| 60 |
+
font-size: 1.1rem;
|
| 61 |
+
color: var(--muted);
|
| 62 |
+
max-width: 600px;
|
| 63 |
+
margin: 0 auto;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/* Endpoint box */
|
| 67 |
+
.endpoint {
|
| 68 |
+
background: var(--accent-light);
|
| 69 |
+
border: 1.5px solid var(--accent);
|
| 70 |
+
border-radius: 10px;
|
| 71 |
+
padding: 1.25rem 1.5rem;
|
| 72 |
+
margin: 2rem 0;
|
| 73 |
+
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
| 74 |
+
font-size: 0.9rem;
|
| 75 |
+
word-break: break-all;
|
| 76 |
+
position: relative;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
.endpoint strong {
|
| 80 |
+
color: var(--text);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* Sections */
|
| 84 |
+
h2 {
|
| 85 |
+
font-size: 1.35rem;
|
| 86 |
+
font-weight: 600;
|
| 87 |
+
margin: 2.5rem 0 1rem;
|
| 88 |
+
color: var(--accent);
|
| 89 |
+
letter-spacing: -0.01em;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
h3 {
|
| 93 |
+
font-size: 1rem;
|
| 94 |
+
font-weight: 600;
|
| 95 |
+
margin: 0 0 0.5rem;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
p, li {
|
| 99 |
+
color: var(--muted);
|
| 100 |
+
margin-bottom: 0.5rem;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
ul {
|
| 104 |
+
list-style: none;
|
| 105 |
+
padding: 0;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
ul li {
|
| 109 |
+
padding: 0.4rem 0;
|
| 110 |
+
padding-left: 1.25rem;
|
| 111 |
+
position: relative;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
ul li::before {
|
| 115 |
+
content: "\203A";
|
| 116 |
+
position: absolute;
|
| 117 |
+
left: 0;
|
| 118 |
+
color: var(--accent);
|
| 119 |
+
font-weight: 700;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/* Cards */
|
| 123 |
+
.card {
|
| 124 |
+
background: var(--card);
|
| 125 |
+
border: 1px solid var(--border);
|
| 126 |
+
border-radius: 10px;
|
| 127 |
+
padding: 1.25rem 1.5rem;
|
| 128 |
+
margin: 0.75rem 0;
|
| 129 |
+
transition: border-color 0.2s, box-shadow 0.2s;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.card:hover {
|
| 133 |
+
border-color: var(--accent);
|
| 134 |
+
box-shadow: 0 2px 12px rgba(37, 99, 235, 0.08);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
/* Code */
|
| 138 |
+
code {
|
| 139 |
+
background: var(--accent-light);
|
| 140 |
+
padding: 0.15em 0.45em;
|
| 141 |
+
border-radius: 5px;
|
| 142 |
+
font-size: 0.85em;
|
| 143 |
+
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
pre {
|
| 147 |
+
background: var(--card);
|
| 148 |
+
border: 1px solid var(--border);
|
| 149 |
+
border-radius: 8px;
|
| 150 |
+
padding: 1rem 1.25rem;
|
| 151 |
+
overflow-x: auto;
|
| 152 |
+
font-size: 0.82rem;
|
| 153 |
+
margin: 0.6rem 0 0;
|
| 154 |
+
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
| 155 |
+
line-height: 1.5;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/* Table */
|
| 159 |
+
table {
|
| 160 |
+
width: 100%;
|
| 161 |
+
border-collapse: collapse;
|
| 162 |
+
margin: 1rem 0;
|
| 163 |
+
font-size: 0.9rem;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
th, td {
|
| 167 |
+
text-align: left;
|
| 168 |
+
padding: 0.7rem 0.85rem;
|
| 169 |
+
border-bottom: 1px solid var(--border);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
th {
|
| 173 |
+
font-weight: 600;
|
| 174 |
+
color: var(--text);
|
| 175 |
+
font-size: 0.8rem;
|
| 176 |
+
text-transform: uppercase;
|
| 177 |
+
letter-spacing: 0.05em;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/* Badge */
|
| 181 |
+
.badge {
|
| 182 |
+
display: inline-block;
|
| 183 |
+
background: var(--accent-gradient);
|
| 184 |
+
color: white;
|
| 185 |
+
padding: 0.2em 0.65em;
|
| 186 |
+
border-radius: 5px;
|
| 187 |
+
font-size: 0.7rem;
|
| 188 |
+
font-weight: 600;
|
| 189 |
+
vertical-align: middle;
|
| 190 |
+
letter-spacing: 0.02em;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
/* Footer */
|
| 194 |
+
footer {
|
| 195 |
+
margin-top: 3.5rem;
|
| 196 |
+
padding-top: 1.5rem;
|
| 197 |
+
border-top: 1px solid var(--border);
|
| 198 |
+
color: var(--muted);
|
| 199 |
+
font-size: 0.85rem;
|
| 200 |
+
text-align: center;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
footer p {
|
| 204 |
+
margin-bottom: 0.25rem;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/* Links */
|
| 208 |
+
a {
|
| 209 |
+
color: var(--accent);
|
| 210 |
+
text-decoration: none;
|
| 211 |
+
transition: opacity 0.2s;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
a:hover {
|
| 215 |
+
text-decoration: underline;
|
| 216 |
+
opacity: 0.85;
|
| 217 |
+
}
|
mcp_server/server.py
CHANGED
|
@@ -12,9 +12,8 @@ from .lifespan import lifespan
|
|
| 12 |
|
| 13 |
_INSTRUCTIONS = (
|
| 14 |
"ClimateQ&A MCP server. Provides retrieval tools over IPCC, IPBES, IPOS "
|
| 15 |
-
"reports (documents and figures)
|
| 16 |
-
"Use `retrieve_data_mcp` for textual report content and figures
|
| 17 |
-
"`retrieve_graphs` for OWID quantitative charts."
|
| 18 |
)
|
| 19 |
|
| 20 |
mcp = FastMCP(
|
|
@@ -26,4 +25,6 @@ mcp = FastMCP(
|
|
| 26 |
# Tool modules decorate directly on `mcp` when imported.
|
| 27 |
# The imports below trigger registration.
|
| 28 |
from .tools.retriever.retrieve_documents import service as _docs_tool # noqa: E402, F401
|
| 29 |
-
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
_INSTRUCTIONS = (
|
| 14 |
"ClimateQ&A MCP server. Provides retrieval tools over IPCC, IPBES, IPOS "
|
| 15 |
+
"reports (documents and figures). "
|
| 16 |
+
"Use `retrieve_data_mcp` for textual report content and figures."
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
mcp = FastMCP(
|
|
|
|
| 25 |
# Tool modules decorate directly on `mcp` when imported.
|
| 26 |
# The imports below trigger registration.
|
| 27 |
from .tools.retriever.retrieve_documents import service as _docs_tool # noqa: E402, F401
|
| 28 |
+
|
| 29 |
+
# OWID graph retrieval — uncomment once the index is confirmed populated:
|
| 30 |
+
# from .tools.retriever.retrieve_graphs import service as _graphs_tool # noqa: E402, F401
|
mcp_server/tests/test_server.py
CHANGED
|
@@ -22,14 +22,12 @@ import json
|
|
| 22 |
from contextlib import asynccontextmanager
|
| 23 |
from dataclasses import dataclass
|
| 24 |
from typing import Any
|
| 25 |
-
|
| 26 |
import pytest
|
| 27 |
from fastmcp import Client, FastMCP
|
| 28 |
|
| 29 |
from mcp_server import mcp
|
| 30 |
from mcp_server.context import AppContext
|
| 31 |
from mcp_server.tools.retriever.retrieve_documents import service as retrieve_documents_svc
|
| 32 |
-
from mcp_server.tools.retriever.retrieve_graphs import service as retrieve_graphs_svc
|
| 33 |
|
| 34 |
|
| 35 |
@dataclass
|
|
@@ -58,34 +56,10 @@ _FAKE_IMAGES = [
|
|
| 58 |
),
|
| 59 |
]
|
| 60 |
|
| 61 |
-
_FAKE_GRAPHS = [
|
| 62 |
-
_StubDoc(
|
| 63 |
-
page_content="CO2 emissions per capita over time.",
|
| 64 |
-
metadata={
|
| 65 |
-
"source": "OWID",
|
| 66 |
-
"url": "https://ourworldindata.org/grapher/co2-emissions-per-capita",
|
| 67 |
-
"similarity_score": 0.87,
|
| 68 |
-
},
|
| 69 |
-
),
|
| 70 |
-
_StubDoc(
|
| 71 |
-
page_content="Renewable energy share by country.",
|
| 72 |
-
metadata={
|
| 73 |
-
"source": "OWID",
|
| 74 |
-
"url": "https://ourworldindata.org/grapher/renewable-energy",
|
| 75 |
-
"similarity_score": 0.42,
|
| 76 |
-
},
|
| 77 |
-
),
|
| 78 |
-
]
|
| 79 |
-
|
| 80 |
-
|
| 81 |
async def _fake_retrieve_documents(*args: Any, **kwargs: Any):
|
| 82 |
return list(_FAKE_DOCS), list(_FAKE_IMAGES)
|
| 83 |
|
| 84 |
|
| 85 |
-
async def _fake_retrieve_graphs(*args: Any, **kwargs: Any):
|
| 86 |
-
return list(_FAKE_GRAPHS)
|
| 87 |
-
|
| 88 |
-
|
| 89 |
@asynccontextmanager
|
| 90 |
async def _fake_lifespan(_server: FastMCP):
|
| 91 |
yield AppContext(
|
|
@@ -101,9 +75,6 @@ def _patch_retrieval(monkeypatch: pytest.MonkeyPatch):
|
|
| 101 |
monkeypatch.setattr(
|
| 102 |
retrieve_documents_svc, "retrieve_documents", _fake_retrieve_documents
|
| 103 |
)
|
| 104 |
-
monkeypatch.setattr(
|
| 105 |
-
retrieve_graphs_svc, "_retrieve_graphs", _fake_retrieve_graphs
|
| 106 |
-
)
|
| 107 |
monkeypatch.setattr(mcp, "_lifespan", _fake_lifespan)
|
| 108 |
|
| 109 |
|
|
@@ -112,11 +83,10 @@ async def test_tools_are_registered() -> None:
|
|
| 112 |
async with Client(mcp) as client:
|
| 113 |
tools = await client.list_tools()
|
| 114 |
names = {t.name for t in tools}
|
| 115 |
-
assert
|
| 116 |
|
| 117 |
by_name = {t.name: t for t in tools}
|
| 118 |
assert by_name["retrieve_data_mcp"].inputSchema["properties"]["query"]["type"] == "string"
|
| 119 |
-
assert by_name["retrieve_graphs"].inputSchema["properties"]["query"]["type"] == "string"
|
| 120 |
|
| 121 |
|
| 122 |
@pytest.mark.asyncio
|
|
@@ -159,26 +129,10 @@ async def test_retrieve_data_mcp_legacy_text_compat() -> None:
|
|
| 159 |
|
| 160 |
|
| 161 |
@pytest.mark.asyncio
|
| 162 |
-
async def
|
| 163 |
-
|
| 164 |
-
result = await client.call_tool("retrieve_graphs", {"query": "co2 emissions"})
|
| 165 |
-
|
| 166 |
-
assert result.structured_content is not None
|
| 167 |
-
payload = result.structured_content
|
| 168 |
-
assert set(payload.keys()) == {"graphs"}
|
| 169 |
-
assert len(payload["graphs"]) == len(_FAKE_GRAPHS)
|
| 170 |
-
|
| 171 |
-
first = payload["graphs"][0]
|
| 172 |
-
assert first["content"] == _FAKE_GRAPHS[0].page_content
|
| 173 |
-
assert first["source"] == "OWID"
|
| 174 |
-
assert first["url"] == _FAKE_GRAPHS[0].metadata["url"]
|
| 175 |
-
assert first["similarity_score"] == pytest.approx(0.87)
|
| 176 |
-
assert first["metadata"] == _FAKE_GRAPHS[0].metadata
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
@pytest.mark.asyncio
|
| 180 |
-
async def test_module_level_mcp_has_both_tools() -> None:
|
| 181 |
-
"""The module-level ``mcp`` instance has both tools registered."""
|
| 182 |
tools = await mcp.list_tools()
|
| 183 |
names = {t.name for t in tools}
|
| 184 |
-
assert
|
|
|
|
|
|
|
|
|
| 22 |
from contextlib import asynccontextmanager
|
| 23 |
from dataclasses import dataclass
|
| 24 |
from typing import Any
|
|
|
|
| 25 |
import pytest
|
| 26 |
from fastmcp import Client, FastMCP
|
| 27 |
|
| 28 |
from mcp_server import mcp
|
| 29 |
from mcp_server.context import AppContext
|
| 30 |
from mcp_server.tools.retriever.retrieve_documents import service as retrieve_documents_svc
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
@dataclass
|
|
|
|
| 56 |
),
|
| 57 |
]
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
async def _fake_retrieve_documents(*args: Any, **kwargs: Any):
|
| 60 |
return list(_FAKE_DOCS), list(_FAKE_IMAGES)
|
| 61 |
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
@asynccontextmanager
|
| 64 |
async def _fake_lifespan(_server: FastMCP):
|
| 65 |
yield AppContext(
|
|
|
|
| 75 |
monkeypatch.setattr(
|
| 76 |
retrieve_documents_svc, "retrieve_documents", _fake_retrieve_documents
|
| 77 |
)
|
|
|
|
|
|
|
|
|
|
| 78 |
monkeypatch.setattr(mcp, "_lifespan", _fake_lifespan)
|
| 79 |
|
| 80 |
|
|
|
|
| 83 |
async with Client(mcp) as client:
|
| 84 |
tools = await client.list_tools()
|
| 85 |
names = {t.name for t in tools}
|
| 86 |
+
assert "retrieve_data_mcp" in names
|
| 87 |
|
| 88 |
by_name = {t.name: t for t in tools}
|
| 89 |
assert by_name["retrieve_data_mcp"].inputSchema["properties"]["query"]["type"] == "string"
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
@pytest.mark.asyncio
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
@pytest.mark.asyncio
|
| 132 |
+
async def test_module_level_mcp_has_tools() -> None:
|
| 133 |
+
"""The module-level ``mcp`` instance has tools registered."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
tools = await mcp.list_tools()
|
| 135 |
names = {t.name for t in tools}
|
| 136 |
+
assert "retrieve_data_mcp" in names
|
| 137 |
+
|
| 138 |
+
|