-
Notifications
You must be signed in to change notification settings - Fork 21
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e50b65
mcpagent cli command
teddyam c272a53
adding mcpagent template to cli
teddyam 34f4a29
removed unnecessary param for hook
teddyam 46dab08
added option for AOAI_MODEL
teddyam d43ede3
changed env vars to match expected from cli
teddyam 3102fa9
small tweaks
teddyam fe57596
adjusted spacing
teddyam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/cli/templates/typescript/mcpagent/appPackage/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions
50
packages/cli/templates/typescript/mcpagent/appPackage/manifest.json.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/cli/templates/typescript/mcpagent/appPackage/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
packages/cli/templates/typescript/mcpagent/package.json.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "preview", | ||
"@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" | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/cli/templates/typescript/mcpagent/src/index.ts.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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('{{ toKebabCase name }}', { level: 'debug' }); | ||
|
||
const app = new App({ | ||
plugins: [new DevtoolsPlugin()], | ||
logger | ||
}); | ||
|
||
const prompt = new ChatPrompt({ | ||
instructions: | ||
`You are an MCP Agent that is tied to the ${process.env.SERVER_NAME} MCP server. | ||
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: 'gpt-4o', | ||
apiKey: process.env.AZURE_OPENAI_API_KEY!, | ||
endpoint: process.env.AZURE_OPENAI_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(); | ||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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