OpenAI MCP Provider¶
This module provides integration with OpenAI Agents SDK, enabling conversion between MCP tools and OpenAI’s tool format.
Overview¶
The primary function in this module is to_openai_tools
, which takes a NostrMCPClient
instance and converts the available MCP tools into a format that can be used by an OpenAI-compatible agent.
Usage¶
from agents import Agent, AsyncOpenAI, OpenAIChatCompletionsModel
from agentstr import NostrMCPClient
from agentstr.mcp.providers.openai import to_openai_tools
# Assume nostr_mcp_client is an initialized and connected NostrMCPClient
async def setup_openai_agent(nostr_mcp_client: NostrMCPClient):
# Convert MCP tools to OpenAI format
openai_tools = await to_openai_tools(nostr_mcp_client)
# Create an OpenAI agent with the converted tools
agent = Agent(
name="openai_agent",
instructions="You are a helpful assistant.",
model=OpenAIChatCompletionsModel(
model="gpt-4-turbo",
openai_client=AsyncOpenAI()
),
tools=openai_tools,
)
return agent
Note
For a complete, working example, check out the OpenAI Agent example.
Reference¶
See Also¶
OpenAI Agent Provider — For using OpenAI agents with Agentstr.
agentstr.mcp.nostr_mcp_client.NostrMCPClient
— The client used to fetch MCP tools.