Skip to content

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

Open
PratikDhanave (PratikDhanave) wants to merge 4 commits into
microsoft:mainfrom
PratikDhanaveFork:openai-hosted-mcp-example
Open

Add a Go example exercising hostedtool.MCPServer with the OpenAI Responses provider#665
PratikDhanave (PratikDhanave) wants to merge 4 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 Automatic risk classification is in progress labels Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Parity Review — Approved ✅

This PR adds examples/02-agents/providers/openai/hosted_mcp/main.go, a pure example addition with no exported API changes.

Upstream mapping: The Go example maps directly to the upstream .NET ResponseAgent_Hosted_MCP sample — same hosted MCP endpoint ((learn.microsoft.com/redacted), same server name (microsoft_learn), same allowed tool (microsoft_docs_search), and same concept of iterating response contents for MCPServerToolCallContentandToolApprovalRequestContent`.

No public API changes: No exported Go identifiers are added or modified; public-api-change label is not applicable.

Pre-existing note (out of scope for this PR): The upstream .NET HostedMcpServerTool exposes an ApprovalMode property (NeverRequire / AlwaysRequire). The Go hostedtool.MCPServer struct does not yet have an equivalent field — this is a pre-existing gap in the struct, not introduced by this PR, and is not a concern for this review.

Generated by Go API Consistency Review Agent · sonnet46 · 26.5 AIC · ⌖ 4.07 AIC · ⊞ 6K ·

@github-actions github-actions Bot added failed-auto-risk Automatic risk classification was inconclusive or failed and removed pending-auto-risk Automatic risk classification is in progress labels Aug 20, 2026
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 failed-auto-risk Automatic risk classification was inconclusive or failed 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.

3 participants