Skip to content

Commit d6b0a24

Browse files
@mcp.tool
def upload_and_index(session_id: str) -> str: """Upload JSON to Gemini File Search deterministically.""" s = _session(session_id) json_path = s.get("json_path") if not json_path or not os.path.exists(json_path): raise ValueError("No JSON found. Run convert_to_json first.") # --- Create the File Search Store with no args to see what happens --- try: store_obj = client.file_search_stores.create() except TypeError as e: # If it fails, try to get helpful error message about what it expects raise TypeError(f"create() signature issue: {e}. Try checking client.file_search_stores.create.__doc__ or __signature__") # Extract the store name if hasattr(store_obj, 'name'): store_name = store_obj.name elif isinstance(store_obj, dict) and 'name' in store_obj: store_name = store_obj['name'] else: raise TypeError(f"Cannot extract name. Type: {type(store_obj)}, Content: {store_obj}") # --- Upload to File Search Store --- with open(json_path, 'rb') as f: op = client.file_search_stores.upload_to_file_search_store( file_search_store_name=store_name, file=f, config={ "display_name": os.path.basename(json_path), "mime_type": "application/json" } ) # --- Poll until indexing is complete --- while not getattr(op, 'done', False): time.sleep(2) op = client.operations.get(name=op.name) s["store_name"] = store_name return f"✅ Uploaded and indexed {json_path} to Gemini File Search store: {store_name}"
1 parent ba1875c commit d6b0a24

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

‎servers/server.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@ def upload_and_index(session_id: str) -> str:
7070
if not json_path or not os.path.exists(json_path):
7171
raise ValueError("No JSON found. Run convert_to_json first.")
7272

73-
# --- Create the File Search Store ---
74-
# Pass the FileSearchStore object as the body parameter
75-
store_obj = client.file_search_stores.create(
76-
body={
77-
"display_name": f"pcap_store_{session_id}"
78-
}
79-
)
73+
# --- Create the File Search Store with no args to see what happens ---
74+
try:
75+
store_obj = client.file_search_stores.create()
76+
except TypeError as e:
77+
# If it fails, try to get helpful error message about what it expects
78+
raise TypeError(f"create() signature issue: {e}. Try checking client.file_search_stores.create.__doc__ or __signature__")
8079

8180
# Extract the store name
8281
if hasattr(store_obj, 'name'):

0 commit comments

Comments
 (0)