Skip to content

Commit a9cd799

Browse files
add docs
1 parent a2f34be commit a9cd799

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

libs/providers/langchain-openai/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,51 @@ const response = await model.invoke("Find information about OpenAI", {
144144

145145
For more information, see [OpenAI's Web Search Documentation](https://platform.openai.com/docs/guides/tools-web-search).
146146

147+
### MCP Tool (Model Context Protocol)
148+
149+
The MCP tool allows OpenAI models to connect to remote MCP servers and OpenAI-maintained service connectors, giving models access to external tools and services.
150+
151+
There are two ways to use MCP tools:
152+
153+
1. **Remote MCP servers**: Connect to any public MCP server via URL
154+
2. **Connectors**: Use OpenAI-maintained wrappers for popular services like Google Workspace or Dropbox
155+
156+
**Remote MCP server** - Connect to any MCP-compatible server:
157+
158+
```typescript
159+
import { ChatOpenAI, tools } from "@langchain/openai";
160+
161+
const model = new ChatOpenAI({ model: "gpt-4o" });
162+
163+
const response = await model.invoke("Roll 2d4+1", {
164+
tools: [
165+
tools.mcp({
166+
serverLabel: "dmcp",
167+
serverDescription: "A D&D MCP server for dice rolling",
168+
serverUrl: "https://dmcp-server.deno.dev/sse",
169+
requireApproval: "never",
170+
}),
171+
],
172+
});
173+
```
174+
175+
**Service connectors** - Use OpenAI-maintained connectors for popular services:
176+
177+
```typescript
178+
const response = await model.invoke("What's on my calendar today?", {
179+
tools: [
180+
tools.mcp({
181+
serverLabel: "google_calendar",
182+
connectorId: "connector_googlecalendar",
183+
authorization: "<oauth-access-token>",
184+
requireApproval: "never",
185+
}),
186+
],
187+
});
188+
```
189+
190+
For more information, see [OpenAI's MCP Documentation](https://platform.openai.com/docs/guides/tools-remote-mcp).
191+
147192
## Embeddings
148193

149194
This package also adds support for OpenAI's embeddings model.

0 commit comments

Comments
 (0)