-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
85 lines (64 loc) · 2.33 KB
/
main.py
File metadata and controls
85 lines (64 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# main.py
from mcp.server.fastmcp import FastMCP
import os
import webbrowser
# Create an MCP server
mcp = FastMCP("AI Sticky Notes")
def create_title_slug(title: str) -> str:
"""
Create a slug from the title for use in filenames.
Parameters:
title (str): The title to be slugged.
Returns:
str: The slugified version of the title.
"""
import re
slug = re.sub(r'[^a-zA-Z0-9]+', '-', title).strip('-')
return slug
@mcp.tool()
def add_note(message: str, claude_response: str) -> str:
"""
Save any prompt and its response as a markdown note file for future reference.
This tool can be used to store information about any topic - technical, historical,
personal, educational, etc.
To save a note, start your question with:
"Please write a sticky note for the following prompt:"
followed by any question or topic you want to save.
The note will be formatted in markdown with:
- Title (your prompt)
- Date
- Your original prompt
- Claude's detailed response
The goal is to build a personal knowledge base of questions and answers
that you can refer back to later.
Parameters:
message (str): The initial prompt/message (your question about any topic)
claude_response (str): Claude's response to save for future reference
Returns:
str: A confirmation message indicating the note was saved.
"""
import datetime
import os
# Create notes directory if it doesn't exist
notes_dir = os.path.join(os.path.dirname(__file__), "notes")
os.makedirs(notes_dir, exist_ok=True)
# Clean the message and create a slug for the filename
cleaned_message = message.strip()
title_slug = create_title_slug(cleaned_message[:50]) # Use first 50 chars for filename
timestamp = datetime.datetime.now()
# Create filename with timestamp to ensure uniqueness
filename = f"{timestamp.strftime('%Y%m%d_%H%M%S')}_{title_slug}.md"
filepath = os.path.join(notes_dir, filename)
# Create markdown content
markdown_content = f"""# {cleaned_message}
## Date
{timestamp.strftime('%Y-%m-%d %H:%M:%S')}
## Initial Prompt
{cleaned_message}
## Claude Response
{claude_response}
"""
# Write the markdown file
with open(filepath, "w") as f:
f.write(markdown_content)
return f"Note saved as {filename}"