-
Notifications
You must be signed in to change notification settings - Fork 22
Adding MCP Agent template to CLI #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3e50b65
c272a53
34f4a29
46dab08
d43ede3
3102fa9
fe57596
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| import { ProjectBuilder } from '../../project'; | ||
|
|
||
| type TemplateHook = (builder: ProjectBuilder) => Promise<void>; | ||
|
|
||
| export const templateHooks: Record<string, TemplateHook> = { | ||
| 'mcpagent': async (builder) => { | ||
| const readline = await import('node:readline/promises'); | ||
| const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); | ||
|
|
||
| const serverName = await rl.question('Enter MCP server name: '); | ||
| const mcpUrl = await rl.question('Enter MCP server URL: '); | ||
| rl.close(); | ||
|
|
||
| // Validate the MCP URL | ||
| const result = z.string().url().safeParse(mcpUrl); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're putting this in "new" but it's very specific to a particular template. |
||
| if (!result.success) { | ||
| console.error('❌ Invalid MCP URL.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Add env variables | ||
| builder.addEnv('SERVER_NAME', serverName); | ||
| builder.addEnv('MCP_URL', mcpUrl); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| { | ||
| "$schema": "https://developer.microsoft.com/json-schemas/teams/v1.20/MicrosoftTeams.schema.json", | ||
| "version": "1.0.0", | ||
| "manifestVersion": "1.20", | ||
| "id": "$\{{TEAMS_APP_ID}}", | ||
| "name": { | ||
| "short": "{{ toKebabCase name }}-$\{{APP_NAME_SUFFIX}}", | ||
| "full": "{{ capitalize name }}" | ||
| }, | ||
| "developer": { | ||
| "name": "Microsoft", | ||
| "websiteUrl": "https://microsoft.com", | ||
| "privacyUrl": "https://privacy.microsoft.com/privacystatement", | ||
| "termsOfUseUrl": "https://www.microsoft.com/legal/terms-of-use" | ||
| }, | ||
| "description": { | ||
| "short": "Agent connected to MCP", | ||
| "full": "This agent integrates with a single MCP server to respond to messages." | ||
| }, | ||
| "icons": { | ||
| "outline": "outline.png", | ||
| "color": "color.png" | ||
| }, | ||
| "accentColor": "#FFFFFF", | ||
| "staticTabs": [ | ||
| { | ||
| "entityId": "conversations", | ||
| "scopes": ["personal"] | ||
| }, | ||
| { | ||
| "entityId": "about", | ||
| "scopes": ["personal"] | ||
| } | ||
| ], | ||
| "bots": [ | ||
| { | ||
| "botId": "$\{{BOT_ID}}", | ||
| "scopes": ["personal", "team", "groupChat"], | ||
| "isNotificationOnly": false, | ||
| } | ||
| ], | ||
| "validDomains": [ | ||
| "$\{{BOT_DOMAIN}}", | ||
| "*.botframework.com" | ||
| ], | ||
| "webApplicationInfo": { | ||
| "id": "$\{{BOT_ID}}", | ||
| "resource": "api://botid-$\{{BOT_ID}}" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "name": "{{ toKebabCase name }}", | ||
| "version": "0.0.0", | ||
| "license": "MIT", | ||
| "private": true, | ||
| "main": "dist/index", | ||
| "types": "dist/index", | ||
| "files": [ | ||
| "dist", | ||
| "README.md" | ||
| ], | ||
| "scripts": { | ||
| "clean": "npx rimraf ./dist", | ||
| "build": "npx tsc", | ||
| "start": "node .", | ||
| "dev": "npx nodemon -w \"./src/**\" -e ts --exec \"node -r ts-node/register -r dotenv/config ./src/index.ts\"", | ||
| "inspect": "npx cross-env SERVER_PORT=9000 npx @modelcontextprotocol/inspector -e NODE_NO_WARNINGS=1 -e PORT=3978 node -r dotenv/config .", | ||
| "dev:teamsfx": "npx cross-env NODE_OPTIONS='--inspect=9239' npx env-cmd -f .env npm run dev", | ||
| "dev:teamsfx:testtool": "npx cross-env NODE_OPTIONS='--inspect=9239' npx env-cmd -f .env npm run dev", | ||
| "dev:teamsfx:launch-testtool": "npx env-cmd --silent -f env/.env.testtool teamsapptester start" | ||
| }, | ||
| "dependencies": { | ||
| "@microsoft/teams.api": "preview", | ||
| "@microsoft/teams.apps": "preview", | ||
| "@microsoft/teams.cards": "preview", | ||
| "@microsoft/teams.common": "preview", | ||
| "@microsoft/teams.dev": "preview", | ||
| "@microsoft/teams.graph": "preview", | ||
| "@microsoft/teams.mcp": "preview", | ||
| "@microsoft/teams.mcpclient": "^2.0.0-preview.8", | ||
|
||
| "@microsoft/teams.openai": "preview", | ||
| "@modelcontextprotocol/sdk": "^1.7.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@modelcontextprotocol/inspector": "^0.6.0", | ||
| "@types/node": "^22.5.4", | ||
| "cross-env": "^7.0.3", | ||
| "dotenv": "^16.4.5", | ||
| "nodemon": "^3.1.4", | ||
| "rimraf": "^6.0.1", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5.4.5", | ||
| "env-cmd": "latest" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { App } from '@microsoft/teams.apps'; | ||
| import { DevtoolsPlugin } from '@microsoft/teams.dev'; | ||
| import { ChatPrompt } from '@microsoft/teams.ai'; | ||
| import { McpClientPlugin } from '@microsoft/teams.mcpclient'; | ||
| import { OpenAIChatModel } from '@microsoft/teams.openai'; | ||
| import { ConsoleLogger } from '@microsoft/teams.common/logging'; | ||
|
|
||
| const logger = new ConsoleLogger("learn-agent", { level: 'debug' }); | ||
teddyam marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const app = new App({ | ||
| plugins: [ | ||
| new DevtoolsPlugin(), | ||
| logger | ||
| ] | ||
| }); | ||
|
|
||
| const prompt = new ChatPrompt({ | ||
| instructions: | ||
| `You are a MCP Agent that is tied to the ${process.env.SERVER_NAME} MCP server. | ||
teddyam marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Your main purpose is to call on tools available from the MCP server. | ||
| For ANY query related to ${process.env.SERVER_NAME}, use the tools to the best of your ability to answer.`, | ||
| model: new OpenAIChatModel({ | ||
| model: process.env.AOAI_MODEL!, | ||
| apiKey: process.env.AOAI_API_KEY!, | ||
| endpoint: process.env.AOAI_ENDPOINT!, | ||
| apiVersion: '2025-04-01-preview' | ||
| }), | ||
| logger, | ||
| }, [new McpClientPlugin({ logger })]) | ||
| .usePlugin('mcpClient', { | ||
| url: process.env.MCP_URL, | ||
| }); | ||
|
|
||
| app.on('message', async ({ send, activity }) => { | ||
| await send({ type: 'typing' }); | ||
| const res = await prompt.send(activity.text); | ||
| console.log(res); | ||
|
|
||
| await send({ type: 'message', text: res.content }); | ||
|
||
| }); | ||
|
|
||
| (async () => { | ||
| await app.start(); | ||
| })(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/tsconfig", | ||
| "compilerOptions": { | ||
| "module": "NodeNext", | ||
| "target": "ESNext", | ||
| "moduleResolution": "NodeNext", | ||
| "strict": true, | ||
| "noImplicitAny": true, | ||
| "declaration": true, | ||
| "inlineSourceMap": true, | ||
| "esModuleInterop": true, | ||
| "allowSyntheticDefaultImports": true, | ||
| "experimentalDecorators": true, | ||
| "emitDecoratorMetadata": false, | ||
| "resolveJsonModule": true, | ||
| "noUnusedLocals": true, | ||
| "noUnusedParameters": true, | ||
| "pretty": true, | ||
| "outDir": "dist", | ||
| "rootDir": "src", | ||
| "types": ["node"] | ||
| }, | ||
| "ts-node": { | ||
| "transpileOnly": true | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** @type {import('tsup').Options} */ | ||
| module.exports = { | ||
| dts: true, | ||
| minify: false, | ||
| bundle: false, | ||
| sourcemap: true, | ||
| treeshake: true, | ||
| splitting: true, | ||
| clean: true, | ||
| outDir: 'dist', | ||
| entry: ['src/index.ts'], | ||
| format: ['cjs'], | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great if the template could provide these, and it would go through all the questions