Add Learn MCP Server tool-calling sample#642
Add Learn MCP Server tool-calling sample#642pdebruin wants to merge 3 commits intomicrosoft:mainfrom
Conversation
Adds a JS sample that uses Foundry Local with the Learn MCP Server to create a doc-grounded Q&A assistant. The model calls a search_docs tool that queries learn.microsoft.com via MCP (JSON-RPC over HTTP), then synthesizes answers from official Microsoft documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@pdebruin is attempting to deploy a commit to the MSFT-AIP Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Adds a new JavaScript sample demonstrating tool-calling with Foundry Local, grounded by Microsoft Learn documentation retrieved via the Learn MCP Server (JSON-RPC over HTTP).
Changes:
- Adds a new JS sample (
samples/js/learn-mcp-tool-calling/) with an interactive CLI assistant that calls asearch_docstool backed by Learn MCP Server. - Updates the JS samples index to include the new sample.
- Updates the top-level samples README to reflect the new JS sample count (13).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| samples/js/learn-mcp-tool-calling/package.json | Adds a runnable Node.js sample package using foundry-local-sdk (+ WinML optional dep). |
| samples/js/learn-mcp-tool-calling/app.js | Implements the CLI assistant, MCP-backed search_docs tool, and a tool-calling loop. |
| samples/js/README.md | Adds the new sample to the JS samples table. |
| samples/README.md | Updates JavaScript sample count from 12 to 13 and mentions Learn MCP Server. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| for (const toolCall of choice.tool_calls) { | ||
| const functionName = toolCall.function.name; | ||
| const args = JSON.parse(toolCall.function.arguments); |
There was a problem hiding this comment.
JSON.parse(toolCall.function.arguments) can throw (missing/empty/invalid JSON) and will crash the sample mid-conversation. Consider a safe parse with a default (e.g., {}) and on parse failure push a role:'tool' error result for that tool_call_id instead of throwing, so the loop can continue gracefully.
| const args = JSON.parse(toolCall.function.arguments); | |
| const rawArguments = typeof toolCall.function.arguments === 'string' && toolCall.function.arguments.trim() !== '' | |
| ? toolCall.function.arguments | |
| : '{}'; | |
| let args; | |
| try { | |
| args = JSON.parse(rawArguments); | |
| } catch (error) { | |
| messages.push({ | |
| role: 'tool', | |
| tool_call_id: toolCall.id, | |
| content: JSON.stringify({ | |
| error: `Invalid tool arguments for ${functionName}: ${error.message}` | |
| }) | |
| }); | |
| continue; | |
| } |
Adds a C# sample that uses Foundry Local with the Learn MCP Server to create a doc-grounded Q&A assistant. Adapted from tutorial-tool-calling with search_docs tool calling learn.microsoft.com via MCP (JSON-RPC). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a C# sample (learn-mcp-tool-calling) that uses Foundry Local with the Learn MCP Server for doc-grounded Q&A. Hardened FormatSearchResults with TryGetProperty throughout and added ValueKind guards to prevent exceptions on unexpected MCP response shapes. Note: all C# tool-calling samples currently crash at runtime due to a Betalgo.Ranul.OpenAI version mismatch in the SDK (microsoft#632). The sample code is correct and will work once the SDK is updated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds JS and C# samples that use Foundry Local with the Learn MCP Server to create a doc-grounded Q&A assistant.
The model calls a
search_docstool that queries learn.microsoft.com via MCP (JSON-RPC over HTTP), then synthesizes answers from official Microsoft documentation. All inference runs locally on-device.JS sample (
samples/js/learn-mcp-tool-calling/):app.js,package.jsonC# sample (
samples/cs/learn-mcp-tool-calling/):Program.cs,LearnMcpToolCalling.csproj,LearnMcpToolCalling.slnREADME updates:
samples/README.md— updated JS count (12 → 13) and C# count (12 → 13)samples/js/README.md— added table entrysamples/cs/README.md— added table entry