Skip to content

Commit c0433a0

Browse files
reticencejishivdeepak
authored andcommitted
update readme
1 parent eb7af6e commit c0433a0

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/sqlite/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ Docker:
111111
docker build -t mcp/sqlite .
112112
```
113113

114+
## Test with MCP inspector
115+
116+
```bash
117+
mcp dev main.py:server
118+
```
119+
114120
## License
115121

116122
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

src/sqlite/src/mcp_server_sqlite/server.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mcp.server.stdio import stdio_server
1313
import mcp.types as types
1414

15+
1516
# reconfigure UnicodeEncodeError prone default (i.e. windows-1252) to utf-8
1617
if sys.platform == "win32" and os.environ.get('PYTHONIOENCODING') is None:
1718
sys.stdin.reconfigure(encoding="utf-8")
@@ -102,7 +103,6 @@
102103
Start your first message fully in character with something like "Oh, Hey there! I see you've chosen the topic {topic}. Let's get started! 🚀"
103104
"""
104105

105-
106106
class SqliteDatabase:
107107
def __init__(self, db_path: str):
108108
self.db_path = str(Path(db_path).expanduser())
@@ -161,7 +161,6 @@ def _execute_query(self, query: str, params: dict[str, Any] | None = None) -> li
161161
logger.error(f"Database error executing query: {e}")
162162
raise
163163

164-
165164
async def main(db_path: str):
166165
logger.info(f"Starting SQLite MCP Server with DB path: {db_path}")
167166

@@ -216,8 +215,7 @@ async def handle_list_prompts() -> list[types.Prompt]:
216215

217216
@server.get_prompt()
218217
async def handle_get_prompt(name: str, arguments: dict[str, str] | None) -> types.GetPromptResult:
219-
logger.debug(
220-
f"Handling get_prompt request for {name} with args {arguments}")
218+
logger.debug(f"Handling get_prompt request for {name} with args {arguments}")
221219
if name != "mcp-demo":
222220
logger.error(f"Unknown prompt: {name}")
223221
raise ValueError(f"Unknown prompt: {name}")
@@ -235,8 +233,7 @@ async def handle_get_prompt(name: str, arguments: dict[str, str] | None) -> type
235233
messages=[
236234
types.PromptMessage(
237235
role="user",
238-
content=types.TextContent(
239-
type="text", text=prompt.strip()),
236+
content=types.TextContent(type="text", text=prompt.strip()),
240237
)
241238
],
242239
)
@@ -347,22 +344,19 @@ async def handle_call_tool(
347344

348345
if name == "read_query":
349346
if not arguments["query"].strip().upper().startswith("SELECT"):
350-
raise ValueError(
351-
"Only SELECT queries are allowed for read_query")
347+
raise ValueError("Only SELECT queries are allowed for read_query")
352348
results = db._execute_query(arguments["query"])
353349
return [types.TextContent(type="text", text=str(results))]
354350

355351
elif name == "write_query":
356352
if arguments["query"].strip().upper().startswith("SELECT"):
357-
raise ValueError(
358-
"SELECT queries are not allowed for write_query")
353+
raise ValueError("SELECT queries are not allowed for write_query")
359354
results = db._execute_query(arguments["query"])
360355
return [types.TextContent(type="text", text=str(results))]
361356

362357
elif name == "create_table":
363358
if not arguments["query"].strip().upper().startswith("CREATE TABLE"):
364-
raise ValueError(
365-
"Only CREATE TABLE statements are allowed")
359+
raise ValueError("Only CREATE TABLE statements are allowed")
366360
db._execute_query(arguments["query"])
367361
return [types.TextContent(type="text", text="Table created successfully")]
368362

@@ -374,7 +368,7 @@ async def handle_call_tool(
374368
except Exception as e:
375369
return [types.TextContent(type="text", text=f"Error: {str(e)}")]
376370

377-
async with stdio_server() as (read_stream, write_stream):
371+
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
378372
logger.info("Server running with stdio transport")
379373
await server.run(
380374
read_stream,
@@ -389,10 +383,8 @@ async def handle_call_tool(
389383
),
390384
)
391385

392-
393386
class ServerWrapper():
394-
"""A helper class which allows you to go with `mcp run` or `mcp dev`"""
395-
387+
396388
async def run(self):
397389
import asyncio
398390
asyncio.run(main("test.db"))

0 commit comments

Comments
 (0)