import { z } from 'zod'
import { ChatOpenAI } from '@langchain/openai'
import { MCPAgent, MCPClient } from 'mcp-use'
// Define the schema using Zod
const WeatherInfo = z.object({
city: z.string().describe('City name'),
temperature: z.number().describe('Temperature in Celsius'),
condition: z.string().describe('Weather condition'),
humidity: z.number().describe('Humidity percentage')
})
// TypeScript type inferred from schema
type WeatherInfo = z.infer<typeof WeatherInfo>
async function main() {
// Setup client and agent
const client = new MCPClient({ mcpServers: {...} })
const llm = new ChatOpenAI({ model: 'gpt-4o' })
const agent = new MCPAgent({ llm, client })
// Get structured output
const weather = await agent.run(
'Get the current weather in San Francisco',
undefined, // maxSteps
undefined, // manageConnector
undefined, // externalHistory
WeatherInfo // output schema
)
console.log(`Temperature in ${weather.city}: ${weather.temperature}°C`)
console.log(`Condition: ${weather.condition}`)
console.log(`Humidity: ${weather.humidity}%`)
await client.closeAllSessions()
}
main().catch(console.error)