Skip to content
85 changes: 81 additions & 4 deletions mcp_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,18 @@ async def get_agent_catalog(original_prompt: str, start_record: int = 1, record_
return {"error": "INTERNAL_ERROR", "details": str(e)}

@core.tool(name="create_agent")
async def create_agent(original_prompt: str, *, agent_name: str, description: str, instruction: str, tools: Optional[List[Dict[str, str]]] = None, knowledge_source: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
async def create_agent(
original_prompt: str,
*,
agent_name: str,
description: str,
instruction: str,
tools: Optional[List[Dict[str, Any]]] = None,
tables: Optional[List[Dict[str, Any]]] = None,
columns: Optional[List[Dict[str, Any]]] = None,
data_source: Optional[List[Dict[str, Any]]] = None,
knowledge_source: Optional[Dict[str, str]] = None,
) -> Dict[str, Any]:
"""
Create and register a new AI agent with defined identity, behavior, and optional integrations.

Expand All @@ -361,6 +372,39 @@ async def create_agent(original_prompt: str, *, agent_name: str, description: st
"name": str,
"description": str
}
A tool may optionally include table metadata it uses:
{
"name": str,
"description": str,
"table": {"name": str}
}
Column metadata must be passed through the top-level `columns` parameter,
not nested inside tool table metadata.

- `tables`: Optional explicit table metadata for the agent or tools:
[
{
"name": str,
"tool_name": str
}
]
Use `tool_name` when the table belongs to a specific tool.
Omit `tool_name` for direct agent-owned tables. Direct tables are represented
as Agent -> Table -> Column; tool-owned tables are represented as
Agent -> Tool -> Table -> Column.

- `columns`: Optional explicit column metadata for tables:
[
{
"name": str,
"table_name": str,
"table_id": str
}
]
Use `table_name` or `table_id` to link each column to its table.

- `data_source`: Optional relationship-style metadata using Agent/Tool/Table/Column
source and target object fields.

- `knowledge_source`: A reference to an external knowledge source that the agent can
use for contextual understanding. If provided, it must follow:
Expand All @@ -384,7 +428,10 @@ async def create_agent(original_prompt: str, *, agent_name: str, description: st
"Revenue Agent") unless the user has explicitly named them or they are confirmed to
exist in the catalog context. If the agent coordinates with upstream agents, describe
their roles generically (e.g. "upstream analytical agents") rather than fabricating names.
tools (Optional[List[Dict[str, str]]]): Optional list of tool definitions.
tools (Optional[List[Dict[str, Any]]]): Optional list of tool definitions.
tables (Optional[List[Dict[str, Any]]]): Optional table definitions.
columns (Optional[List[Dict[str, Any]]]): Optional column definitions.
data_source (Optional[List[Dict[str, Any]]]): Optional data-source relationships.
knowledge_source (Optional[Dict[str, str]]): Optional knowledge source definition.

Returns:
Expand All @@ -403,6 +450,9 @@ async def create_agent(original_prompt: str, *, agent_name: str, description: st
"description": description,
"instruction": instruction,
"tools": tools,
"tables": tables,
"columns": columns,
"data_source": data_source,
"knowledge_source": knowledge_source,
},
tenant_id,
Expand All @@ -413,6 +463,9 @@ async def create_agent(original_prompt: str, *, agent_name: str, description: st
description=description,
instruction=instruction,
tools=tools,
tables=tables,
columns=columns,
data_source=data_source,
knowledge_source=knowledge_source,
tenant_id=tenant_id,
)
Expand Down Expand Up @@ -719,12 +772,12 @@ async def remove_ai_use_case_agent_relationship(original_prompt: str, *, agent_c
return {"error": "INTERNAL_ERROR", "details": str(e)}

@core.tool(name="update_agent")
async def update_agent(original_prompt: str, *, agent_id: Optional[str] = None, agent_name: Optional[str] = None, description: Optional[str] = None, instruction: Optional[str] = None, tools: Optional[List[Dict[str, str]]] = None, knowledge_source: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
async def update_agent(original_prompt: str, *, agent_id: Optional[str] = None, agent_name: Optional[str] = None, description: Optional[str] = None, instruction: Optional[str] = None, tools: Optional[List[Dict[str, str]]] = None, knowledge_source: Optional[Dict[str, str]] = None, tables: Optional[List[Dict[str, Any]]] = None, columns: Optional[List[Dict[str, Any]]] = None, data_source: Optional[List[Dict[str, Any]]] = None) -> Dict[str, Any]:
"""
Update an existing AI agent’s configuration.

Allows modification of agent metadata such as name, description,
behavior instructions, tools, and knowledge sources.
behavior instructions, tools, knowledge sources, tables, and columns.

Args:
original_prompt (str): REQUIRED. Exact user message verbatim.
Expand All @@ -736,6 +789,24 @@ async def update_agent(original_prompt: str, *, agent_id: Optional[str] = None,
confirmed to exist. Describe inter-agent dependencies generically if unknown.
tools (Optional[List[Dict[str, str]]]): Updated tool list.
knowledge_source (Optional[Dict[str, str]]): Updated knowledge source.
tables (Optional[List[Dict[str, Any]]]): Tables to rename or update. Each entry must include
the new name and a way to identify the existing table:
{
"name": str, # new table name to set
"old_name": str, # current table name (use when table_id is unknown)
"table_id": str # table identifier (preferred when available)
}
Use "old_name" when the user refers to the current name (e.g. "rename
SNOW_incident to Incidents"). Use "table_id" when you already know it.
columns (Optional[List[Dict[str, Any]]]): Columns to rename. Each entry must include
the new name and a way to identify the existing column:
{
"name": str, # new column name to set
"old_name": str, # current column name (required)
"table_id": str # table the column belongs to (preferred for precision)
}
Use "old_name" for the current column name (e.g. "rename col_id to incident_id").
Provide "table_id" when the same column name exists in multiple tables.

Returns:
Dict[str, Any]: Updated agent metadata or error response.
Expand All @@ -756,6 +827,9 @@ async def update_agent(original_prompt: str, *, agent_id: Optional[str] = None,
"instruction": instruction,
"tools": tools,
"knowledge_source": knowledge_source,
"tables": tables,
"columns": columns,
"data_source": data_source,
},
tenant_id,
)
Expand All @@ -767,6 +841,9 @@ async def update_agent(original_prompt: str, *, agent_id: Optional[str] = None,
instruction=instruction,
tools=tools,
knowledge_source=knowledge_source,
tables=tables,
columns=columns,
data_source=data_source,
tenant_id=str(tenant_id),
)

Expand Down
Loading