|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "37868ee2", |
| 6 | + "metadata": { |
| 7 | + "language_info": { |
| 8 | + "name": "polyglot-notebook" |
| 9 | + }, |
| 10 | + "polyglot_notebook": { |
| 11 | + "kernelName": "csharp" |
| 12 | + } |
| 13 | + }, |
| 14 | + "source": [ |
| 15 | + "## HTTP Context\n", |
| 16 | + "\n", |
| 17 | + "This project illustrates how to access the HttpContext from tool calls. See the [README](../README.md) for more details.\n" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "markdown", |
| 22 | + "id": "093a7d4f", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "### Examples\n", |
| 26 | + "\n", |
| 27 | + "The following request illustrates a tool call that retrieves the HTTP headers from the [HttpContext] using the [IHttpContextAccessor].\n", |
| 28 | + "\n", |
| 29 | + "The server implements two other tools, `get_request_info` and `get_user_claims`. You can modify the code below to call these tools as well,\n", |
| 30 | + "which illustrate how to access other parts of the [HttpContext].\n", |
| 31 | + "\n", |
| 32 | + "\n", |
| 33 | + "[HttpContext]: https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httpcontext\n", |
| 34 | + "[IHttpContextAccessor]: https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.http.ihttpcontextaccessor" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "code", |
| 39 | + "execution_count": 4, |
| 40 | + "id": "3324ec56", |
| 41 | + "metadata": { |
| 42 | + "language_info": { |
| 43 | + "name": "polyglot-notebook" |
| 44 | + }, |
| 45 | + "polyglot_notebook": { |
| 46 | + "kernelName": "pwsh" |
| 47 | + } |
| 48 | + }, |
| 49 | + "outputs": [ |
| 50 | + { |
| 51 | + "name": "stdout", |
| 52 | + "output_type": "stream", |
| 53 | + "text": [ |
| 54 | + "{\n", |
| 55 | + " \"result\": {\n", |
| 56 | + " \"content\": [\n", |
| 57 | + " {\n", |
| 58 | + " \"type\": \"text\",\n", |
| 59 | + " \"text\": \"[]\"\n", |
| 60 | + " }\n", |
| 61 | + " ],\n", |
| 62 | + " \"structuredContent\": {\n", |
| 63 | + " \"result\": []\n", |
| 64 | + " }\n", |
| 65 | + " },\n", |
| 66 | + " \"id\": 1,\n", |
| 67 | + " \"jsonrpc\": \"2.0\"\n", |
| 68 | + "}\n" |
| 69 | + ] |
| 70 | + } |
| 71 | + ], |
| 72 | + "source": [ |
| 73 | + "curl -s -X POST http://localhost:3001 `\n", |
| 74 | + "-H \"ProtocolVersion: 2025-06-18\" `\n", |
| 75 | + "-H \"Accept: application/json, text/event-stream\" `\n", |
| 76 | + "-H \"Content-Type: application/json\" `\n", |
| 77 | + "-d '{\n", |
| 78 | + " \"jsonrpc\": \"2.0\",\n", |
| 79 | + " \"id\": 1,\n", |
| 80 | + " \"method\": \"tools/call\",\n", |
| 81 | + " \"params\": {\n", |
| 82 | + " \"name\": \"get_user_claims\"\n", |
| 83 | + " }\n", |
| 84 | + "}' | Where-Object { $_ -like \"data:*\" } | ForEach-Object { $_.Substring(5) } | jq" |
| 85 | + ] |
| 86 | + } |
| 87 | + ], |
| 88 | + "metadata": { |
| 89 | + "kernelspec": { |
| 90 | + "display_name": ".NET (C#)", |
| 91 | + "language": "C#", |
| 92 | + "name": ".net-csharp" |
| 93 | + }, |
| 94 | + "language_info": { |
| 95 | + "name": "polyglot-notebook" |
| 96 | + }, |
| 97 | + "polyglot_notebook": { |
| 98 | + "kernelInfo": { |
| 99 | + "defaultKernelName": "csharp", |
| 100 | + "items": [ |
| 101 | + { |
| 102 | + "aliases": [], |
| 103 | + "languageName": "csharp", |
| 104 | + "name": "csharp" |
| 105 | + } |
| 106 | + ] |
| 107 | + } |
| 108 | + } |
| 109 | + }, |
| 110 | + "nbformat": 4, |
| 111 | + "nbformat_minor": 5 |
| 112 | +} |
0 commit comments