Spaces:
Sleeping
Sleeping
Update server.py
Browse files
server.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
from fastmcp import FastMCP
|
|
|
|
|
|
|
| 2 |
import logging
|
| 3 |
import os
|
| 4 |
|
|
@@ -145,7 +147,31 @@ SOURCE:
|
|
| 145 |
</source_material>
|
| 146 |
"""
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
|
|
|
|
|
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|
| 151 |
print("Starting FastMCP server on port 7860...")
|
|
|
|
| 1 |
from fastmcp import FastMCP
|
| 2 |
+
from fastmcp import FastMCP, Context
|
| 3 |
+
from fastmcp.server.elicitation import AcceptedElicitation
|
| 4 |
import logging
|
| 5 |
import os
|
| 6 |
|
|
|
|
| 147 |
</source_material>
|
| 148 |
"""
|
| 149 |
|
| 150 |
+
@mcp.tool
|
| 151 |
+
async def analyze_file(ctx: Context, file: bytes) -> str:
|
| 152 |
+
"""
|
| 153 |
+
Example tool that:
|
| 154 |
+
1. Receives a file
|
| 155 |
+
2. If type is ambiguous, asks for clarification
|
| 156 |
+
3. Then returns a processed summary
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
# 1) Basic file info
|
| 160 |
+
info = f"Received file of size {len(file)} bytes."
|
| 161 |
+
|
| 162 |
+
# 2) Elicit choice if needed
|
| 163 |
+
result = await ctx.elicit(
|
| 164 |
+
message="What is the file type (text/image/pdf)?",
|
| 165 |
+
response_type=["text", "image", "pdf"]
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
if result.action == "accept":
|
| 169 |
+
file_type = result.data
|
| 170 |
+
else:
|
| 171 |
+
return "Elicitation declined or cancelled"
|
| 172 |
|
| 173 |
+
# 3) Do some processing based on type
|
| 174 |
+
return f"{info} User said type: {file_type}"
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|
| 177 |
print("Starting FastMCP server on port 7860...")
|