Skip to content

Commit 01876dd

Browse files
committed
feat: add a prompt to search on Django docs website
Signed-off-by: Rai Siqueira <rai93siqueira@gmail.com>
1 parent 43e8d8f commit 01876dd

File tree

6 files changed

+121
-9
lines changed

6 files changed

+121
-9
lines changed

opencode.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"$schema": "https://opencode.ai/config.json",
33
"mcp": {
4-
"django-mcp": {
4+
"local-django-telescope": {
55
"type": "local",
6-
"command": "uv",
7-
"args": ["run", "django-mcp", "--settings", "testproject.settings"],
8-
"env": {
9-
"PYTHONPATH": "./fixtures/testproject"
10-
}
6+
"command": [
7+
"/Users/rai/Developer/vinta/django-mcp/.venv/bin/django-telescope",
8+
"--settings",
9+
"testproject.settings"
10+
],
11+
"environment": {
12+
"PYTHONPATH": "/Users/rai/Developer/vinta/django-mcp/fixtures/testproject"
13+
},
1114
}
1215
}
1316
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "django-telescope"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
description = "A Model Context Protocol (MCP) server for Django applications, inspired by Laravel Boost"
55
readme = "README.md"
66
authors = [

server.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"url": "https://github.com/raisiqueira/django-telescope",
77
"source": "github"
88
},
9-
"version": "0.1.2",
9+
"version": "0.1.3",
1010
"packages": [
1111
{
1212
"registryType": "pypi",

src/django_telescope/server_fastmcp.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,43 @@ async def reverse_url(
429429
return {"error": f"Error reversing URL: {str(e)}"}
430430

431431

432+
@mcp.prompt()
433+
async def search_django_docs(topic: str) -> str:
434+
"""
435+
Generate a prompt to help search for specific topics in Django documentation.
436+
437+
Args:
438+
topic: The Django topic or feature to search for (e.g., "models", "queryset", "migrations", "authentication")
439+
440+
Returns:
441+
A formatted prompt to help the user search Django documentation effectively.
442+
"""
443+
django_version = django.get_version()
444+
major_version = ".".join(django_version.split(".")[:2])
445+
446+
prompt = f"""I need help finding information about "{topic}" in Django documentation.
447+
448+
Current Django version: {django_version}
449+
450+
Please help me by:
451+
1. Searching the official Django documentation at https://docs.djangoproject.com/en/{major_version}/
452+
2. Providing relevant links to documentation pages about "{topic}"
453+
3. Explaining key concepts and best practices
454+
4. Showing code examples if applicable
455+
456+
Focus on documentation that is relevant to Django {major_version} to ensure compatibility with my project.
457+
458+
Key areas to consider:
459+
- Core concepts and usage patterns
460+
- API reference and method signatures
461+
- Common pitfalls and solutions
462+
- Related topics that might be helpful
463+
464+
Please provide clear, actionable information with direct links to the official documentation."""
465+
466+
return prompt
467+
468+
432469
def run_server(settings_module: str | None = None, transport: str = "stdio"):
433470
"""
434471
Run the Django MCP server.

test_prompt.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python
2+
"""
3+
Test the search_django_docs prompt.
4+
5+
Note: FastMCP prompts are designed to be called by MCP clients, not directly in Python.
6+
This test demonstrates the prompt is properly registered and shows what it would return.
7+
"""
8+
import asyncio
9+
import os
10+
import sys
11+
12+
# Add fixtures project to path
13+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "fixtures", "testproject"))
14+
15+
# Set Django settings
16+
os.environ["DJANGO_SETTINGS_MODULE"] = "testproject.settings"
17+
18+
# Import Django and setup
19+
import django
20+
21+
django.setup()
22+
23+
# Import the server and inspect the prompt
24+
from django_telescope.server_fastmcp import mcp
25+
26+
27+
async def test_search_django_docs_prompt():
28+
"""Test that the search_django_docs prompt is registered and callable."""
29+
print("Testing search_django_docs prompt registration...\n")
30+
print("=" * 80)
31+
32+
# List all registered prompts
33+
prompts = await mcp._list_prompts()
34+
print(f"Found {len(prompts)} registered prompt(s):\n")
35+
36+
for prompt in prompts:
37+
print(f"✓ Prompt: {prompt.name}")
38+
print(f" Description: {prompt.description}")
39+
print(f" Arguments: {[arg.name for arg in prompt.arguments]}")
40+
print()
41+
42+
# Check if our prompt is registered
43+
prompt_names = [p.name for p in prompts]
44+
if "search_django_docs" in prompt_names:
45+
print("✓ search_django_docs prompt is registered successfully!")
46+
print()
47+
print("To use this prompt, connect an MCP client and call:")
48+
print(' mcp.get_prompt("search_django_docs", arguments={"topic": "models"})')
49+
print()
50+
print("=" * 80)
51+
print("\nExample usage in MCP Inspector or Claude Desktop:\n")
52+
print("1. Configure the MCP server in your client")
53+
print("2. Use the prompt with a topic, e.g., 'models', 'queryset', etc.")
54+
print("3. The prompt will generate a formatted request to search Django docs")
55+
print("=" * 80)
56+
else:
57+
print("✗ search_django_docs prompt not found!")
58+
59+
# Demonstrate what the prompt function would return for a sample topic
60+
print("\nSample output for topic='models':")
61+
print("-" * 80)
62+
# Access the underlying function through the prompt
63+
from django_telescope.server_fastmcp import search_django_docs
64+
65+
# Get the underlying function
66+
result = await search_django_docs.fn("models")
67+
print(result)
68+
print("=" * 80)
69+
70+
71+
if __name__ == "__main__":
72+
asyncio.run(test_search_django_docs_prompt())

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)