Przemyslaw Chachaj commited on
Commit
7271b67
·
1 Parent(s): b019af3

FIX working minimal MCP server

Browse files
Files changed (1) hide show
  1. app.py +22 -38
app.py CHANGED
@@ -1,53 +1,37 @@
1
  import gradio as gr
2
 
3
- # === TOOLS ===
4
 
5
- def create_contract(link: str, uid: str = "default", category: str = "general"):
6
  """
7
- Create a habit contract from link (Instagram reel / article / etc.)
8
 
9
  Args:
10
- link: URL to content (reel / video / article).
11
- uid: User id (e.g. "szef_1").
12
- category: Habit category (e.g. "career", "health").
13
- """
14
- return {
15
- "status": "created",
16
- "uid": uid,
17
- "source": link,
18
- "category": category
19
- }
20
 
21
-
22
- def next_step(uid: str):
23
  """
24
- Returns next habit step for contract holder.
 
25
 
26
- Args:
27
- uid: User id that has a contract.
 
 
 
 
28
 
29
- Returns:
30
- Text with next step.
31
- """
32
- return f"Next step for {uid}: do one tiny action now."
33
 
 
 
34
 
35
- # === UI (opcjonalne, dla podglądu) ===
 
 
36
 
37
- demo = gr.Interface(
38
- fn=create_contract,
39
- inputs=[
40
- gr.Textbox(label="Link"),
41
- gr.Textbox(label="UID", value="szef_1"),
42
- gr.Textbox(label="Category", value="career"),
43
- ],
44
- outputs="json",
45
- title="Habit Agent MCP Server",
46
- description="Create habit contracts and get next steps via MCP tools."
47
- )
48
 
49
- # Ten tool nie ma UI, ale jest widoczny jako MCP tool:
50
- gr.api(next_step)
51
 
52
- # 🚀 KRYTYCZNE: MCP SERVER
53
- demo.launch(mcp_server=True)
 
1
  import gradio as gr
2
 
 
3
 
4
+ def create_contract(link: str, category: str = "general") -> dict:
5
  """
6
+ Create a simple habit contract from a reel link.
7
 
8
  Args:
9
+ link: URL to the reel / content.
10
+ category: Area of life (e.g. career, health, relationships).
 
 
 
 
 
 
 
 
11
 
12
+ Returns:
13
+ JSON with a fake uid, echo of params and first tiny step.
14
  """
15
+ if not link:
16
+ return {"error": "link is required"}
17
 
18
+ return {
19
+ "uid": f"demo_{category}",
20
+ "link": link,
21
+ "category": category,
22
+ "next_step": "Watch the reel and take ONE practical action today."
23
+ }
24
 
 
 
 
 
25
 
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("# Behavior Changer – MCP Demo")
28
 
29
+ link = gr.Textbox(label="Reel/link", placeholder="https://instagram.com/reel/...")
30
+ category = gr.Textbox(label="Category", value="career")
31
+ out = gr.JSON(label="Result JSON")
32
 
33
+ btn = gr.Button("Generate Contract")
34
+ btn.click(create_contract, [link, category], out)
 
 
 
 
 
 
 
 
 
35
 
 
 
36
 
37
+ demo.launch(mcp_server=True)