sumitasthaai commited on
Commit
ed7c1bd
·
unverified ·
1 Parent(s): 004218a

add push data

Browse files
Files changed (2) hide show
  1. server.py +98 -1
  2. tasks.db +0 -0
server.py CHANGED
@@ -5,12 +5,34 @@ import requests
5
  from bs4 import BeautifulSoup
6
  from urllib.parse import urljoin, urlparse
7
  import json
8
- from typing import List, Dict, Optional
 
9
 
10
  mcp = FastMCP("tatva-sumit")
11
 
12
  BASE_URL = "https://tatva.sumityadav.com.np"
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def _fetch_page_content(url: str) -> Dict[str, str]:
15
  """Helper function to fetch and parse content from a specific page URL"""
16
  try:
@@ -145,6 +167,81 @@ def get_posts_by_year(year: str) -> List[Dict[str, str]]:
145
  year_posts = [post for post in all_posts if post["path"].startswith(f"{year}/")]
146
  return year_posts
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  # ========================================================================
149
  # SAFE-MCP SECURITY TEST TOOLS - These tools contain deliberate vulnerabilities
150
  # for testing SAFE-T1001 (Tool Poisoning) and SAFE-T1501 (Schema Poisoning)
 
5
  from bs4 import BeautifulSoup
6
  from urllib.parse import urljoin, urlparse
7
  import json
8
+ from typing import List, Dict, Optional, Any
9
+ import sqlite3
10
 
11
  mcp = FastMCP("tatva-sumit")
12
 
13
  BASE_URL = "https://tatva.sumityadav.com.np"
14
 
15
+ # SQLite database setup
16
+ DB_PATH = "tasks.db"
17
+
18
+ def init_db():
19
+ """Initialize the SQLite database and create tasks table if it doesn't exist"""
20
+ conn = sqlite3.connect(DB_PATH)
21
+ cursor = conn.cursor()
22
+ cursor.execute("""
23
+ CREATE TABLE IF NOT EXISTS tasks (
24
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
25
+ task TEXT NOT NULL,
26
+ time_date TEXT NOT NULL,
27
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
28
+ )
29
+ """)
30
+ conn.commit()
31
+ conn.close()
32
+
33
+ # Initialize database on module load
34
+ init_db()
35
+
36
  def _fetch_page_content(url: str) -> Dict[str, str]:
37
  """Helper function to fetch and parse content from a specific page URL"""
38
  try:
 
167
  year_posts = [post for post in all_posts if post["path"].startswith(f"{year}/")]
168
  return year_posts
169
 
170
+ @mcp.tool
171
+ def put_task_to_db(task: str, time_date: str) -> Dict[str, Any]:
172
+ """Add a task to the database with its associated date and time
173
+
174
+ Args:
175
+ task: The task description as a string
176
+ time_date: The date and time for the task (e.g., "2025-01-15 14:30:00")
177
+
178
+ Returns:
179
+ A dictionary with status and the inserted task information
180
+ """
181
+ try:
182
+ conn = sqlite3.connect(DB_PATH)
183
+ cursor = conn.cursor()
184
+ cursor.execute("""
185
+ INSERT INTO tasks (task, time_date)
186
+ VALUES (?, ?)
187
+ """, (task, time_date))
188
+ conn.commit()
189
+ task_id = cursor.lastrowid
190
+ conn.close()
191
+
192
+ return {
193
+ "status": "success",
194
+ "message": "Task added successfully",
195
+ "id": task_id,
196
+ "task": task,
197
+ "time_date": time_date
198
+ }
199
+ except Exception as e:
200
+ return {
201
+ "status": "error",
202
+ "message": f"Failed to add task: {str(e)}"
203
+ }
204
+
205
+ @mcp.tool
206
+ def get_task_from_db(today_date: str) -> List[Dict[str, Any]]:
207
+ """Get all tasks from the database for a specific date
208
+
209
+ Args:
210
+ today_date: The date to retrieve tasks for (e.g., "2025-01-15")
211
+
212
+ Returns:
213
+ A list of dictionaries containing all tasks for the specified date
214
+ """
215
+ try:
216
+ conn = sqlite3.connect(DB_PATH)
217
+ cursor = conn.cursor()
218
+ # Query tasks where time_date starts with the given date
219
+ cursor.execute("""
220
+ SELECT id, task, time_date, created_at
221
+ FROM tasks
222
+ WHERE time_date LIKE ?
223
+ ORDER BY time_date ASC
224
+ """, (f"{today_date}%",))
225
+
226
+ rows = cursor.fetchall()
227
+ conn.close()
228
+
229
+ tasks = []
230
+ for row in rows:
231
+ tasks.append({
232
+ "id": row[0],
233
+ "task": row[1],
234
+ "time_date": row[2],
235
+ "created_at": row[3]
236
+ })
237
+
238
+ return tasks
239
+ except Exception as e:
240
+ return [{
241
+ "status": "error",
242
+ "message": f"Failed to retrieve tasks: {str(e)}"
243
+ }]
244
+
245
  # ========================================================================
246
  # SAFE-MCP SECURITY TEST TOOLS - These tools contain deliberate vulnerabilities
247
  # for testing SAFE-T1001 (Tool Poisoning) and SAFE-T1501 (Schema Poisoning)
tasks.db ADDED
Binary file (12.3 kB). View file