Skip to content

Commit 7989d20

Browse files
author
Jove Zhong
authored
Move to official FastMCP, add lengthy prompt to improve SQL generation (#8)
* update mcp, fastmcp and tp connect version * replace fastmcp with mcp * adding 2k lines of prompt * Update prompt_template.py * 0.1.4 and update README * Update uv.lock
1 parent 7f2b147 commit 7989d20

File tree

6 files changed

+1809
-49
lines changed

6 files changed

+1809
-49
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ An MCP server for Timeplus.
77

88
## Features
99

10+
### Prompts
11+
12+
* `generate_sql` to give LLM more knowledge about how to query Timeplus via SQL
13+
1014
### Tools
1115

1216
* `run_sql`
@@ -92,7 +96,7 @@ TIMEPLUS_KAFKA_CONFIG={"bootstrap.servers":"a.aivencloud.com:28864", "sasl.mecha
9296

9397
3. Run `uv sync` to install the dependencies. Then do `source .venv/bin/activate`.
9498

95-
4. For easy testing, you can run `fastmcp dev mcp_timeplus/mcp_server.py` to start the MCP server. Click the "Connect" button to connect the UI with the MCP server, then switch to the "Tools" tab to run the available tools.
99+
4. For easy testing, you can run `mcp dev mcp_timeplus/mcp_server.py` to start the MCP server. Click the "Connect" button to connect the UI with the MCP server, then switch to the "Tools" tab to run the available tools.
96100

97101
### Environment Variables
98102

mcp_timeplus/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
list_kafka_topics,
77
explore_kafka_topic,
88
create_kafka_stream,
9+
generate_sql,
910
)
1011

1112
__all__ = [
@@ -16,4 +17,5 @@
1617
"list_kafka_topics",
1718
"explore_kafka_topic",
1819
"create_kafka_stream",
20+
"generate_sql",
1921
]

mcp_timeplus/mcp_server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import timeplus_connect
55
from timeplus_connect.driver.binding import quote_identifier, format_query_value
66
from dotenv import load_dotenv
7-
from fastmcp import FastMCP
7+
from mcp.server.fastmcp import FastMCP
88

99
MCP_SERVER_NAME = "mcp-timeplus"
1010
from mcp_timeplus.mcp_env import config
11+
from mcp_timeplus.prompt_template import TEMPLATE
1112

1213
import json, os, time
1314
from confluent_kafka.admin import (AdminClient)
@@ -128,6 +129,10 @@ def run_sql(query: str):
128129
logger.error(f"Error executing query: {err}")
129130
return f"error running query: {err}"
130131

132+
@mcp.prompt()
133+
def generate_sql(requirements: str) -> str:
134+
return f"Please generate Timeplus SQL for the requirement:\n\n{requirements}\n\nMake sure following the guide {TEMPLATE}"
135+
131136
@mcp.tool()
132137
def list_kafka_topics():
133138
logger.info("Listing all topics in the Kafka cluster")

0 commit comments

Comments
 (0)