Skip to content

Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider - #665

Merged
Quim Muntal (qmuntal) merged 6 commits into
microsoft:mainfrom
PratikDhanaveFork:openai-hosted-mcp-example
Aug 27, 2026
Merged

Quim Muntal (qmuntal) merged 6 commits into
microsoft:mainfrom
PratikDhanaveFork:openai-hosted-mcp-example

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

Adds a new example examples/02-agents/providers/openai/hosted_mcp/main.go that wires a hosted MCP server into an OpenAI Responses agent.

The example:

  • builds an OpenAI Responses agent via openaiprovider.NewResponsesAgent,
  • attaches []tool.Tool{&hostedtool.MCPServer{...}} pointing at the public Microsoft Learn MCP endpoint (https://learn.microsoft.com/api/mcp) with AllowedTools set,
  • runs the agent and iterates the response contents, printing any *message.MCPServerToolCallContent and hosted-MCP *message.ToolApprovalRequestContent,
  • guards the live run behind an OPENAI_API_KEY check, printing a skip message when it is absent (consistent with the other provider examples).

It is registered in the cmd/verifyexamples harness alongside the existing hosted-tool examples (foundry step14_code_interpreter, step21_web_search, step23_local_mcp).

Why

provider/openaiprovider/responses.go already maps *hostedtool.MCPServer onto responses.ToolMcpParam (server label, server URL/connector id, description, allowed tools, headers, authorization), but no example exercised it — hostedtool.MCPServer did not appear anywhere under examples/. The existing examples only wired hostedtool for CodeInterpreter and WebSearch. This mirrors the .NET and Python SDKs, which each ship a hosted-MCP agent sample, and fills the missing OpenAI Responses variant for cross-SDK parity. The example follows the same structure as the existing hosted-tool step examples.

Testing

  • go build ./...
  • go vet ./examples/... ./cmd/verifyexamples/...
  • go test ./cmd/verifyexamples/...

all pass. The example is a docs/example addition; its live body is env-gated so it compiles and vets without credentials.

Copilot AI review requested due to automatic review settings July 23, 2026 08:21
@PratikDhanave
PratikDhanave (PratikDhanave) requested a review from a team as a code owner July 23, 2026 08:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new OpenAI Responses provider example demonstrating how to wire a hosted MCP server (hostedtool.MCPServer) into an agent, and registers that example with the cmd/verifyexamples harness.

Changes:

  • Added examples/02-agents/providers/openai/hosted_mcp/main.go to run an OpenAI Responses agent with the Microsoft Learn hosted MCP endpoint and print MCP tool-call / approval-request contents.
  • Registered the new example in cmd/verifyexamples/examples.go so it can be verified (env-gated on OPENAI_API_KEY).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
examples/02-agents/providers/openai/hosted_mcp/main.go New example showing a hosted MCP server tool used through an OpenAI Responses agent and printing MCP-related response contents.
cmd/verifyexamples/examples.go Adds the new hosted MCP example to the verifyexamples registry with OPENAI_API_KEY gating.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/02-agents/providers/openai/hosted_mcp/main.go
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 23, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Add examples/02-agents/providers/openai/hosted_mcp demonstrating the
hostedtool.MCPServer tool with an OpenAI Responses agent. It attaches a
remote hosted MCP server (Microsoft Learn), runs the agent, and inspects
the response for MCPServerToolCallContent and MCP approval requests. The
live run is guarded behind an OPENAI_API_KEY check. Register the example
in the verifyexamples harness alongside the other hosted-tool examples.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

# Conflicts:
#	cmd/verifyexamples/examples.go
@github-actions github-actions Bot added area:examples Changes files in the examples area area:tooling Changes files in the tooling area size:medium At most 100 changed lines across at most 5 files pending-auto-risk labels Aug 20, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

API Consistency Review

Scope: examples
Changed Go contract: None — no exported Go APIs modified
Upstream evidence reviewed:

  • Python: python/samples/02-agents/providers/openai/client_with_hosted_mcp.py — OpenAIChatClient with hosted MCP tools and approval workflow
  • .NET: dotnet/samples/02-agents/ModelContextProtocol/ResponseAgent_Hosted_MCP/Program.cs — ResponseAgent with hosted MCP server
    Result: aligned

This PR adds examples/02-agents/providers/openai/hosted_mcp/main.go, which demonstrates hostedtool.MCPServer with the OpenAI Responses provider. No exported Go APIs are changed.

The example directly mirrors upstream counterparts in both Python (client_with_hosted_mcp.py) and .NET (ResponseAgent_Hosted_MCP), all three using the same hosted MCP server pattern: attach a server-side MCP server by URL, restrict allowed tools, and handle tool-call content and optional approval requests in the response. The Go example is semantically aligned with those upstream samples.

The existing parity-approved label is correct. No parity issues found.

Generated by Go API Consistency Review Agent · sonnet46 · 20.7 AIC · ⌖ 4.99 AIC · ⊞ 6.4K · ◷

@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Aug 27, 2026
Merged via the queue into microsoft:main with commit 1da9987 Aug 27, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:examples Changes files in the examples area area:tooling Changes files in the tooling area parity-approved Go API consistency review found no parity issues size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants