Skip to content

feat(mcp): expose server instructions from InitializeResult on MCPClient#1814

Merged
poshinchen merged 1 commit intostrands-agents:mainfrom
ShotaroKataoka:feat/mcp-server-instructions
Mar 6, 2026
Merged

feat(mcp): expose server instructions from InitializeResult on MCPClient#1814
poshinchen merged 1 commit intostrands-agents:mainfrom
ShotaroKataoka:feat/mcp-server-instructions

Conversation

@ShotaroKataoka
Copy link
Contributor

Description

Store InitializeResult.instructions on MCPClient.server_instructions so Host applications can access MCP server instructions and inject them into the LLM's system prompt.

The MCP specification defines instructions in InitializeResult for servers to provide LLMs with contextual knowledge about tool interdependencies and operational constraints. Currently MCPClient discards the InitializeResult, making instructions inaccessible to Host applications.

Changes:

  • mcp_client.py: Store init_result.instructions after session.initialize() (3 lines added)
  • conftest.py: Fix mock to return proper InitializeResult with instructions field
  • test_mcp_client.py: Add 2 tests (default empty string, populated from server)

The SDK's responsibility is only to make the data accessible — how/whether to inject into the system prompt remains the Host's decision.

Related Issues

Closes #1813

Documentation PR

N/A — Public attribute server_instructions is self-documenting. Docs update can follow if needed.

Type of Change

New feature

Testing

  • 2106 passed, 2 failed (pre-existing failures unrelated to this PR — region-dependent default model prefix apac vs us)
  • 128 MCP tests all pass
  • 2 new tests added

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

Assessment: Comment

This is a well-scoped, minimal change that exposes MCP server instructions to Host applications - aligning with the MCP specification. The implementation is clean and tests are included.

Review Summary
  • API Design: The existing review comment covers the key improvement - using str | None instead of str with empty string default to distinguish between "no instructions" vs "empty instructions"
  • Code Organization: Public attribute should be positioned before private attributes
  • Testing: Good coverage with tests for both the default case and populated instructions

Small, focused feature addition. Once the requested changes are addressed, this looks good to merge.

Store InitializeResult.instructions on MCPClient.server_instructions
so Host applications can access MCP server instructions and inject
them into the LLM's system prompt.

The MCP specification defines instructions as a way for servers to
provide LLMs with contextual knowledge about tool interdependencies
and operational constraints. Clients like Claude Code and VSCode
already support this feature.

Closes strands-agents#1813
@ShotaroKataoka ShotaroKataoka force-pushed the feat/mcp-server-instructions branch from 583ded4 to ba91fba Compare March 6, 2026 00:47
@github-actions github-actions bot added size/s and removed size/s labels Mar 6, 2026
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Assessment: Approve ✅

The requested changes have been addressed:

  1. Type annotation: Changed to str | None = None - correctly distinguishes "server didn't provide instructions" (None) from "server provided empty instructions" ("")
  2. Attribute position: Moved above _consumers
  3. Tests updated: Now correctly asserts is None for the default case

Clean implementation that aligns with the MCP specification. Ready to merge.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@poshinchen poshinchen merged commit 316f54e into strands-agents:main Mar 6, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Expose MCP Server instructions from InitializeResult on MCPClient

4 participants