Sync upstream updates: MCP skills and AI tool input streaming

Merged
BI
11m ago
+3939-193

Laravel Updates

  • laravel/mcp#410 — Add support for the MCP Skills extension (io.modelcontextprotocol/skills), including Skill, DirectorySkill, SkillResource, skills/list and skills/get methods, resources/list and resources/read integration, make:mcp-skill generator and stubs, dependencies in src/mcp/composer.json, and skills documentation.
  • laravel/ai#1250 — Flag failed tool results with is_error: true when mapping messages for Anthropic.
  • laravel/ai#1249 — Port Anthropic prompt-cache test verifying the tools cache breakpoint skips deferred tools and consolidate Hypervel's prior deferred-tool test case under it.
  • laravel/ai#1251 — Port Anthropic native structured-output tool-choice tests through ToolChoiceAgent while retaining middleware and thinking coverage.
  • laravel/ai#1245 — Capture and replay reasoning fields across OpenAI-compatible tool loops and delegate DeepSeek message mapping to the shared chat-completion mapper while keeping DeepSeek's empty reasoning_content fallback.
  • laravel/ai#1241 — Port Groq and OpenAI AG-UI tool-result replay mapping tests verifying paired provider call IDs.
  • laravel/ai#1239 — Stream tool input as it arrives via ToolInputStart, ToolInputDelta, and ToolInputError events across all text gateways, Anthropic eager input streaming, TextGenerationLoop, AgentUserInteractionProtocol, VercelDataProtocol, and AI SDK docs.
  • laravel/ai#1233 — Honor the Strict attribute on Mistral and OpenRouter tools through MapsChatCompletionTools::supportsStrictTools() and update the AI SDK strict-tools documentation.
  • laravel/ai#1261 — Update default, cheapest, and smartest text models in config/ai.php and the Anthropic, Azure OpenAI, Bedrock, Gemini, OpenAI, and OpenRouter providers.

Additional Hypervel changes

  • Clone resolved Skill instances in ServerContext::resolveSkills() so auto-singletoned skill classes do not share once() frontmatter caches across calls in the same coroutine, and register Skill::flushState() in AfterEachTestSubscriber for static attribute metadata cleanup.
  • Replace protected TextGenerationLoop::unfinishedToolInputs() with in-place trackUnfinishedToolInput(array &$toolInputs, StreamEvent $event): void to avoid quadratic copy-on-write string copying across streamed tool-input deltas, and document the protected-helper difference in src/ai/README.md.
  • Extend BroadcastBatcher to batch adjacent ToolInputDelta events by invocation and tool ID, keeping ToolCall ordering intact, and update config/ai.php, src/ai/README.md, src/docs/ai-sdk.md, and src/docs/porting-from-laravel.md.
  • Keep Bedrock's synthetic structured_output tool internal during streaming so generateStreamStep() with a schema does not emit ToolInputStart or ToolInputDelta events for it.
  • Keep resultId null in AgentUserInteraction::toolResultFrom() and document why client- or hydrator-assigned AG-UI message IDs are not copied into provider call_id fields when mappers already pair calls and results on toolCallId.
  • Keep Anthropic's synthetic output_structured_data tool internal during streaming without enabling eager_input_streaming on it, preserve explicit eager_input_streaming values in Anthropic provider options with ??= true, drop malformed Anthropic streamed tool inputs regardless of stop reason (preserving signed thinking replay when another valid tool call remains), and strip length-cut-off tool calls and raw replay blocks on cut-off steps across Anthropic, Bedrock, Cohere, Gemini, and OpenAI.
  • Cast unfinished tool-input keys to string in TextGenerationLoop::unfinishedToolInputErrors() for numeric tool IDs, and populate replayBlocksProvider in TextGenerationLoop::buildAssistantMessage() so in-memory messages strip foreign replay blocks across providers.
  • Filter unsupported temperature and topP sampling parameters on Bedrock Claude 4.7+ and 5.x models (and drop topP when temperature is set on compatible Claude models) in BedrockTextGateway::buildConverseParameters().
  • Send x-anthropic-beta: structured-outputs-2025-11-13 by default in CreatesOpenRouterClient::client() (overridable via configured headers) so OpenRouter enforces strict: true on Claude tool definitions.
  • Preserve custom skills/list and skills/get handlers registered in boot() via ??= in Server::detectSkillsCapability(), and reject empty normalized skill slugs in MakeSkillCommand::handle().

[!NOTE]

Add MCP skills extension and AI tool-input streaming across providers

  • Adds the MCP skills feature: a Skill base class, skills/list and skills/get server methods, skill resources in resource listing, and a make:mcp-skill generator command with published stubs. Skills are declared on Server and resolved through ServerContext::skills(), with support for class names, instances, and directory paths.
  • Adds tool-input streaming to all AI gateways via a shared StreamsToolInput concern. Streams now emit ToolInputStart and ToolInputDelta events as tool-call arguments arrive, and ToolInputError for incomplete inputs. Cut-off tool calls (Length finish reason with incomplete JSON) are not invoked and are excluded from replay blocks.
  • Maps the new tool-input events to AG-UI (TOOL_CALL_START, TOOL_CALL_ARGS, TOOL_CALL_END) and Vercel data protocol parts; BroadcastBatcher batches tool-input deltas with matching invocation and tool IDs.
  • Adds strict-tool support for Mistral and OpenRouter (supportsStrictTools(), plus the x-anthropic-beta structured-outputs header for OpenRouter), is_error flagging on failed Anthropic tool results, eager input streaming for Anthropic, and updated default/smartest model fallbacks across providers.
  • Risk: incomplete streamed tool inputs now produce ToolInputError events and are never invoked — check TextGenerationLoop::trackUnfinishedToolInput() and each gateway's HandlesTextStreaming if consumers rely on cut-off calls being emitted with empty arguments. Bedrock requests drop sampling parameters for incompatible Claude models (Claude 5, 4.7, Fable) in BedrockTextGateway::buildConverseParameters().

Macroscope summarized 13c33f7.

Summary by CodeRabbit

  • New Features
    • Streamed tool inputs now show arguments as they arrive across supported AI providers. Incomplete inputs are reported as errors rather than invoked.
    • Added MCP Skills support, including discovery, retrieval, resource access, and a command to create skills.
    • Mistral and OpenRouter now support strict tool definitions.
  • Improvements
    • Agent broadcasts can batch tool-input deltas.
    • Updated default AI models across several providers.
    • Failed Anthropic tool results are now marked as errors.
    • Reasoning is preserved when replaying compatible-provider conversations.
  • Documentation
    • Added MCP Skills guidance and updated AI streaming documentation.