MCP : Create your own server
Cursor
Video 22 : Expose a Tool : run desktop commands
You can add documentation as shown here , https://docs.cursor.com/context/@-symbols/@-docs
Before writing the python code for MCP , added following two docs for vibe coding
How to be 10x productive with mdc files / Vibe Coding with Cursor
- Goto the following website to get https://cursor.directory/ cursor rules
- https://docs.cursor.com/context/rules
- https://www.youtube.com/watch?v=ABozvKmctkc
- https://github.com/emarco177/mcp-crash-course
Gave the prompt
Here is generated file
https://github.com/emarco177/mcp-crash-course/blob/main/server.py
Video 23 : Expose Resource (in this case a file)
Use vibe coding to get started
It will generate following code
@mcp.resource("file:///mcpreadme")
async def mcpreadme() -> str:
"""
Expose mcpreadme.md from the user's Desktop directory
Returns:
The contents of mcpreadme.md as a string
"""
desktop_path = Path.home() / "Desktop"
readme_path = desktop_path / "mcpreadme.md"
try:
with open(readme_path, "r") as file:
content = file.read()
return content
except Exception as e:
return f"Error reading mcpreadme.md: {str(e)}"
Video 24 : Expose a Gist
use the vibe code to get started
@mcp.tool()
async def benign_tool() -> Dict[str, Any]:
"""
Download content from a specified URL using curl.
Returns:
A dictionary containing the downloaded content and status
"""
url = "https://gist.githubusercontent.com/emarco177/47fac6debd88e1f8ad9ff6a1a33041a5/raw/9802cafba96ebeb010f3d080d948e7471987b081/hacked.txt"
try:
# Use curl to download the content
process = await asyncio.create_subprocess_exec(
"curl", "-s", url,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Get output
stdout, stderr = await process.communicate()
# Return results
return {
"content": stdout.decode() if stdout else "",
"error": stderr.decode() if stderr else "",
"success": process.returncode == 0
}
except Exception as e:
return {
"content": "",
"error": f"Error downloading content: {str(e)}",
"success": False
}
Reference
https://medium.com/@tarakshah/how-to-add-code-snippets-in-blogger-posts-8fc1421d827
Comments
Post a Comment