set_organization
Set the organization for all subsequent API calls in SingleStore MCP Server. Use this after logging in to select the target organization by ID or name, ensuring all API requests align with the chosen organization.
Instructions
Select which SingleStore organization to use for all subsequent API calls.
This tool must be called after logging in and before making other API requests.
Once set, all API calls will target the selected organization until changed.
Args:
orgID: Name or ID of the organization to select
Returns:
Dictionary with the selected organization ID and name
Usage:
- Call get_organizations first to see available options
- Then call this tool with either the organization's name or ID
- All subsequent API calls will use the selected organization
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ctx | No | ||
| orgID | Yes |
Implementation Reference
- The main handler function for the 'set_organization' tool. It validates the provided organization_id against available organizations, sets it in the config settings, and returns success or error details.async def set_organization(ctx: Context, organization_id: str) -> dict: """ Set the current organization after retrieving the list from choose_organization. This tool should only be used when the client doesn't support elicitation. Args: organization_id: The ID of the organization to select, as obtained from the choose_organization tool's response. Returns: Dictionary with selected organization details Important: - This tool should only be called after choose_organization returns a 'pending_selection' status - The organization_id must be one of the IDs returned by choose_organization Example flow: 1. Call choose_organization first 2. If it returns 'pending_selection', get the organization ID from the list 3. Call set_organization with the chosen ID """ settings = config.get_settings() user_id = config.get_user_id() # Track tool call event settings.analytics_manager.track_event( user_id, "tool_calling", {"name": "set_organization", "organization_id": organization_id}, ) logger.debug(f"Setting organization ID: {organization_id}") try: # Get the list of organizations to validate the selection organizations = query_graphql_organizations() # Find the selected organization selected_org = next( (org for org in organizations if org["orgID"] == organization_id), None ) if not selected_org: available_orgs = ", ".join(org["orgID"] for org in organizations) return { "status": "error", "message": f"Organization ID '{organization_id}' not found. Available IDs: {available_orgs}", "errorCode": "INVALID_ORGANIZATION", "errorDetails": { "provided_id": organization_id, "available_ids": [org["orgID"] for org in organizations], }, } # Set the selected organization in settings if hasattr(settings, "org_id"): settings.org_id = selected_org["orgID"] else: setattr(settings, "org_id", selected_org["orgID"]) await ctx.info( f"Organization set to: {selected_org['name']} (ID: {selected_org['orgID']})" ) return { "status": "success", "message": f"Successfully set organization to: {selected_org['name']} (ID: {selected_org['orgID']})", "data": { "organization": selected_org, }, "metadata": { "timestamp": datetime.now(timezone.utc).isoformat(), "user_id": user_id, }, } except Exception as e: logger.error(f"Error setting organization: {str(e)}") return { "status": "error", "message": f"Failed to set organization: {str(e)}", "errorCode": "ORGANIZATION_SET_FAILED", "errorDetails": {"exception_type": type(e).__name__}, }
- src/api/tools/tools.py:24-35 (registration)Import of the set_organization function and its inclusion in the central tools_definition list used for creating and registering MCP tools.from src.api.tools.organization import ( organization_info, choose_organization, set_organization, ) # Define the tools with their metadata tools_definition = [ {"func": get_user_info}, {"func": organization_info}, {"func": choose_organization}, {"func": set_organization},
- src/api/tools/registery.py:58-66 (registration)Registration logic in the tool registry that conditionally skips registering set_organization when using API key authentication in local mode.# List of tools to exclude when using API key authentication api_key_excluded_tools = ["choose_organization", "set_organization"] for tool in filtered_tools: func = tool.func # Skip organization-related tools when using API key authentication if using_api_key and func.__name__ in api_key_excluded_tools: continue mcp.tool(name=func.__name__, description=func.__doc__)(func)
- src/api/tools/organization/__init__.py:3-5 (registration)Re-export of the set_organization function from the organization module for convenient import in tools.py.from .organization import organization_info, choose_organization, set_organization __all__ = ["organization_info", "choose_organization", "set_organization"]