query_users
Search and retrieve user data from the culinary recipes database to manage user profiles and access information.
Instructions
Queries the 'users' collection of the 'recipies' MongoDB database.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- main.py:402-411 (handler)The asynchronous handler function that executes the 'query_users' tool. It connects to a local MongoDB instance, queries the 'users' collection in the 'recipies' database with the provided query (or empty), converts the documents to JSON-serializable format using _to_jsonable, and returns the list.
async def query_users(query: Optional[Dict] = None) -> List[Dict]: """Interroge la collection 'users' de la base de données MongoDB 'recipies'.""" client = MongoClient('mongodb://localhost:27017/') db = client['recipies'] collection = db['users'] query = query or {} docs = list(collection.find(query)) client.close() return [_to_jsonable(doc) for doc in docs] - main.py:398-401 (registration)The @mcp.tool decorator that registers the 'query_users' tool with the MCP server, specifying its name and description.
@mcp.tool( name="query_users", description="Queries the 'users' collection of the 'recipies' MongoDB database.", ) - main.py:25-38 (helper)Helper utility function used by 'query_users' (and similar tools) to recursively convert MongoDB documents containing ObjectId and datetime objects into JSON-serializable dictionaries.
def _to_jsonable(doc: Dict[str, any]) -> Dict[str, any]: out = {} for k, v in doc.items(): if isinstance(v, ObjectId): out[k] = str(v) elif isinstance(v, datetime): out[k] = v.isoformat() elif isinstance(v, dict): out[k] = _to_jsonable(v) elif isinstance(v, list): out[k] = [_to_jsonable(x) if isinstance(x, dict) else x for x in v] else: out[k] = v return out