MCP Advanced Guide (v2.0.7)
This page documents the production MCP model in ConvEngine 2.0.7, including planner guardrails, post-phase rules, and MCP context metadata used by ce_rule JSON_PATH.
Read order
- MCP Basics
- MCP Advanced Guide (this page)
- MCP HTTP Tool
- MCP Deep Dive
- MCP Example 1
- MCP Example 2
- MCP Example 3
Phase names (current)
PRE_RESPONSE_RESOLUTIONPOST_AGENT_INTENTPOST_AGENT_MCPPOST_TOOL_EXECUTION
Compatibility note: legacy values (PIPELINE_RULES, AGENT_POST_INTENT, AGENT_POST_MCP, TOOL_POST_EXECUTION) are normalized at runtime.
Tool execution paths
Planner MCP path (McpToolStep)
- Planner returns
CALL_TOOLorANSWER. - Tool results are appended to
context.mcp.observations. - For
ANSWER, final text is written tocontext.mcp.finalAnswer. - Rules run in phase
POST_AGENT_MCP. - Response resolution runs after rule transitions.
Direct tool path (ToolOrchestrationStep)
- Request contains
tool_request. - Exactly one tool executes.
- Result stored in
inputParams.tool_resultandcontext.mcp.toolExecution. - Rules run in phase
POST_TOOL_EXECUTION. - Response resolution runs with updated state/context.
Guardrail blocked answer semantics
When MCP_STATUS=GUARDRAIL_BLOCKED_NEXT_TOOL:
McpToolStepwrites fallback text (McpConstants.FALLBACK_GUARDRAIL_BLOCKED) tocontext.mcp.finalAnswer.- Rules in
POST_AGENT_MCPstill execute. ce_responseremains the final response authority (commonlyDERIVEDusingcontext.mcp.finalAnswer).
MCP metadata model for rules
context.mcp.lifecycle:
phase,status,outcome,finishedblocked,error,errorMessagelastAction,lastToolCode,lastToolGroup,lastToolArgstoolExecuted
context.mcp.toolExecution:
phase,status,outcome,finishederror,scopeMismatch,toolExecutedtoolCode,toolGroup,meta,result,errorMessage
JSON_PATH patterns you can use in ce_rule.match_pattern
$[?(@.context.mcp.lifecycle.finished == true && @.context.mcp.lifecycle.outcome == 'BLOCKED')]
$[?(@.context.mcp.lifecycle.error == true)]
$[?(@.context.mcp.toolExecution.phase == 'POST_TOOL_EXECUTION' && @.context.mcp.toolExecution.status == 'SUCCESS')]
$[?(@.context.mcp.toolExecution.scopeMismatch == true)]
Direct tool example (POST_TOOL_EXECUTION)
User asks: Check order ORD-7017 status.
{
"tool_request": {
"tool_code": "mock.order.status",
"tool_group": "HTTP_API",
"args": { "orderId": "ORD-7017" }
}
}
Execution:
ToolOrchestrationStepexecutes one tool.- Writes
tool_result+tool_status=SUCCESS. - Writes
context.mcp.toolExecution.*. - Executes
POST_TOOL_EXECUTIONrules. - Example: rule sets state to
ORDER_SUBMITTED_DIAGNOSISwhen tool status is submitted.
ce_mcp_tool and ce_mcp_planner scoping rules
intent_code and state_code are mandatory (no null/blank scope).
Allowed values:
intent_code: definedce_intent.intent_codeorANYorUNKNOWNstate_code: values present ince_rule.state_codeorANYorUNKNOWN
Invalid scope rows are blocked at startup by static scope validation.
Planner prompt source (ce_mcp_planner)
Planner prompt selection:
- exact
intent_code + state_code - exact
intent_code + ANY - global
ANY + ANY - legacy fallback (
ce_configMcpPlannerkeys) if planner rows are unavailable
SQL snippets
- Planner Rows
- Tool Rows
INSERT INTO ce_mcp_planner (planner_id, intent_code, state_code, system_prompt, user_prompt, enabled)
VALUES
(1001, 'ANY', 'ANY', '...', '...', true),
(1002, 'LOAN_APPLICATION', 'ELIGIBILITY_GATE', '...', '...', true);
INSERT INTO ce_mcp_tool (tool_id, tool_code, tool_group, intent_code, state_code, enabled, description)
VALUES
(9001, 'db.knowledge.graph', 'DB', 'ANY', 'ANY', true, 'DB knowledge graph'),
(9002, 'order.status.api', 'HTTP_API', 'ANY', 'ANY', true, 'Order status API');
For MCP chains, keep final user text in ce_response/ce_prompt_template and treat context.mcp.finalAnswer as a derived source, not the final transport payload.