feat: create tools using MCP

This commit is contained in:
Abhishek Kumar 2026-05-31 16:50:44 +05:30
parent 5c29b6ed94
commit fcb7004c7a
17 changed files with 1989 additions and 572 deletions

View file

@ -36,6 +36,11 @@ The guide tool is the authoritative source for prompt-authoring craft (turn-taki
## Call order
### Creating a reusable tool
1. If authentication is needed, call `list_credentials` and use an existing `credential_uuid`; the user creates credential secrets in the UI.
2. Build a typed tool definition and call `create_tool`. The request schema is authoritative for allowed tool categories and config fields.
3. Use the returned `tool_uuid` in workflow node `tool_uuids`, then call `create_workflow` or `save_workflow`.
### Reading documentation
1. `search_docs` use first for keyword or acronym lookup when the user is asking how Dograh works or how to configure something.
2. `read_doc` fetch the full page once one result looks likely. Prefer this over reasoning from search summaries alone.

View file

@ -13,6 +13,7 @@ from api.mcp_server.tools.docs_search import list_docs, read_doc, search_docs
from api.mcp_server.tools.get_workflow_code import get_workflow_code
from api.mcp_server.tools.node_types import get_node_type, list_node_types
from api.mcp_server.tools.save_workflow import save_workflow
from api.mcp_server.tools.tool_creation import create_tool
from api.mcp_server.tools.voice_prompting_guide import get_voice_prompting_guide
from api.mcp_server.tools.workflows import get_workflow, list_workflows
@ -20,6 +21,7 @@ mcp = FastMCP("dograh", instructions=DOGRAH_MCP_INSTRUCTIONS)
for _tool in (
create_workflow,
create_tool,
get_node_type,
get_workflow,
get_workflow_code,

View file

@ -0,0 +1,63 @@
"""MCP tool for creating reusable Dograh tools."""
from __future__ import annotations
from typing import Any
from pydantic import ValidationError as PydanticValidationError
from api.mcp_server.auth import authenticate_mcp_request
from api.mcp_server.tracing import traced_tool
from api.schemas.tool import CreateToolRequest
from api.services.tool_management import ToolManagementError, create_tool_for_user
def _error_result(code: str, message: str, **extra: Any) -> dict[str, Any]:
return {"created": False, "error_code": code, "error": message, **extra}
@traced_tool
async def create_tool(request: CreateToolRequest) -> dict[str, Any]:
"""Create a reusable tool the agent can invoke during calls.
The request schema is the same `CreateToolRequest` used by the REST API
and generated SDKs. Use it to create HTTP API, end-call, transfer-call,
calculator, or MCP-server tools. For authenticated HTTP or MCP tools,
reference an existing `credential_uuid` from `list_credentials`; users
create credential secrets in the UI, and this flow only stores the UUID
reference. For MCP tools, the server best-effort discovers the remote
tool catalog and caches it in `definition.config.discovered_tools`.
On success, returns `created: true` and the new `tool_uuid`; use that
UUID in workflow node `tool_uuids`. On failure, returns `created: false`,
a machine-readable `error_code`, and a human-readable `error`. Possible
`error_code` values:
- `validation_error` the request failed schema validation.
- `credential_not_found` a supplied credential_uuid is not in this
organization; ask the user to create/select it in the UI first.
- `organization_required` the API key user has no selected organization.
- `create_failed` unexpected persistence or backend failure; retry once,
then surface the error.
"""
user = await authenticate_mcp_request()
try:
parsed_request = CreateToolRequest.model_validate(request)
except PydanticValidationError as e:
return _error_result("validation_error", str(e))
try:
tool = await create_tool_for_user(parsed_request, user, source="mcp")
except ToolManagementError as e:
return _error_result(e.error_code, e.message)
except Exception as e: # noqa: BLE001
return _error_result("create_failed", str(e))
return {
"created": True,
"tool_uuid": tool.tool_uuid,
"name": tool.name,
"category": tool.category,
"status": tool.status,
"definition": tool.definition,
}