Skip to content

Commit b73d6d7

Browse files
committed
Prompt: Add instructions (system prompt) to MCP server
1 parent e2e12f2 commit b73d6d7

File tree

6 files changed

+72
-28
lines changed

6 files changed

+72
-28
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
update to [MCP spec 2025-06-18].
88
- OCI: Added building OCI standard image `cratedb-mcp`
99
- OCI: Added building OCI image `cratedb-mcpo` for Open WebUI
10+
- Prompt: Added instructions (system prompt) to MCP server.
11+
Thanks, @hammerhead and @WalBeh.
1012

1113
[FastMCP 2.10]: https://github.com/jlowin/fastmcp/releases/tag/v2.10.0
1214
[MCP spec 2025-06-18]: https://modelcontextprotocol.io/specification/2025-06-18/changelog

cratedb_mcp/__main__.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import importlib.resources
2+
3+
from cratedb_about.instruction import GeneralInstructions
14
from fastmcp import FastMCP
25
from fastmcp.tools import Tool
36

@@ -10,19 +13,13 @@
1013
query_sql,
1114
)
1215

13-
# Create FastMCP application object.
14-
mcp: FastMCP = FastMCP(__appname__)
15-
16+
instructions_general = GeneralInstructions().render()
17+
instructions_mcp = (importlib.resources.files("cratedb_mcp") / "instructions.md").read_text()
1618

17-
# ------------------------------------------
18-
# Health / Status
19-
# ------------------------------------------
20-
mcp.add_tool(
21-
Tool.from_function(
22-
fn=get_cluster_health,
23-
description="Return the health of the CrateDB cluster.",
24-
tags={"health", "monitoring", "status"},
25-
)
19+
# Create FastMCP application object.
20+
mcp: FastMCP = FastMCP(
21+
name=__appname__,
22+
instructions=instructions_mcp + instructions_general,
2623
)
2724

2825

@@ -31,15 +28,17 @@
3128
# ------------------------------------------
3229
mcp.add_tool(
3330
Tool.from_function(
34-
fn=query_sql,
35-
description="Send an SQL query to CrateDB. Only 'SELECT' queries are allowed.",
31+
fn=get_table_metadata,
32+
description="Return column schema and metadata for all tables stored in CrateDB. "
33+
"Use it to inquire entities you don't know about.",
3634
tags={"text-to-sql"},
3735
)
3836
)
3937
mcp.add_tool(
4038
Tool.from_function(
41-
fn=get_table_metadata,
42-
description="Return an aggregation of all CrateDB's schema, tables and their metadata.",
39+
fn=query_sql,
40+
description="Send an SQL query to CrateDB and return results. "
41+
"Only 'SELECT' queries are allowed.",
4342
tags={"text-to-sql"},
4443
)
4544
)
@@ -64,3 +63,15 @@
6463
tags={"documentation"},
6564
)
6665
)
66+
67+
68+
# ------------------------------------------
69+
# Health / Status
70+
# ------------------------------------------
71+
mcp.add_tool(
72+
Tool.from_function(
73+
fn=get_cluster_health,
74+
description="Return the health of the CrateDB cluster.",
75+
tags={"health", "monitoring", "status"},
76+
)
77+
)

cratedb_mcp/instructions.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## MCP tool instructions
2+
3+
Use all available tools from the CrateDB MCP server `cratedb-mcp` for accurate information.
4+
5+
You have the following tools available:
6+
1. `get_table_metadata`: Return column schema and metadata for all tables stored in CrateDB. Use it to inquire entities you don't know about.
7+
2. `query_sql`: Execute SQL query on CrateDB and return results.
8+
3. `get_cratedb_documentation_index`: Returns the table of contents for the CrateDB documentation. If in doubt about CrateDB-specific syntax, you can obtain the documentation here.
9+
4. `fetch_cratedb_docs`: Once a specific link within the CrateDB documentation is identified, you can download its content here by providing the link.
10+
11+
Try to reason and give an interpretation of the result.
12+

cratedb_mcp/tool.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55
from cratedb_mcp.util.sql import sql_is_permitted
66

77

8-
# ------------------------------------------
9-
# Health / Status
10-
# ------------------------------------------
11-
def get_cluster_health() -> dict:
12-
"""Query sys.health ordered by severity."""
13-
return query_cratedb(Queries.HEALTH)
14-
15-
168
# ------------------------------------------
179
# Text-to-SQL
1810
# ------------------------------------------
@@ -58,3 +50,11 @@ def fetch_cratedb_docs(link: str) -> str:
5850
if not documentation_index.url_permitted(link):
5951
raise ValueError(f"Link is not permitted: {link}")
6052
return documentation_index.client.get(link, timeout=Settings.http_timeout()).text
53+
54+
55+
# ------------------------------------------
56+
# Health / Status
57+
# ------------------------------------------
58+
def get_cluster_health() -> dict:
59+
"""Query sys.health ordered by severity."""
60+
return query_cratedb(Queries.HEALTH)

pyproject.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ dependencies = [
7373
"attrs",
7474
"cachetools<7",
7575
"click<9",
76-
"cratedb-about==0.0.5",
76+
"cratedb-about==0.0.6",
7777
"fastmcp>=2.7,<2.11",
7878
"hishel<0.2",
7979
"pueblo==0.0.11",
@@ -94,6 +94,15 @@ optional-dependencies.test = [
9494

9595
scripts.cratedb-mcp = "cratedb_mcp.cli:cli"
9696

97+
[tool.setuptools]
98+
include-package-data = true
99+
100+
[tool.setuptools.package-data]
101+
cratedb_mcp = [ "*.md" ]
102+
103+
[tool.setuptools.packages.find]
104+
namespaces = false
105+
97106
[tool.ruff]
98107
line-length = 100
99108

@@ -132,9 +141,6 @@ lint.per-file-ignores."tests/*" = [
132141
"S101", # Allow use of `assert`.
133142
]
134143

135-
[tool.setuptools.packages.find]
136-
namespaces = false
137-
138144
[tool.pytest.ini_options]
139145
addopts = """
140146
-rfEXs -p pytester --strict-markers --verbosity=3

tests/test_instructions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from cratedb_mcp.__main__ import mcp
2+
3+
4+
def test_instructions():
5+
instructions_text = mcp.instructions
6+
7+
# MCP instructions.
8+
assert "MCP tool instructions" in instructions_text
9+
10+
# General instructions.
11+
assert "Things to remember when working with CrateDB" in instructions_text
12+
assert "Rules for writing SQL queries" in instructions_text
13+
assert "Core writing principles" in instructions_text

0 commit comments

Comments
 (0)