* Add doc with sample on accessing HttpContext * Apply suggestions from PR review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
112 lines
2.7 KiB
Text
112 lines
2.7 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "37868ee2",
|
|
"metadata": {
|
|
"language_info": {
|
|
"name": "polyglot-notebook"
|
|
},
|
|
"polyglot_notebook": {
|
|
"kernelName": "csharp"
|
|
}
|
|
},
|
|
"source": [
|
|
"## HTTP Context\n",
|
|
"\n",
|
|
"This project illustrates how to access the HttpContext from tool calls. See the [README](../README.md) for more details.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "093a7d4f",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Examples\n",
|
|
"\n",
|
|
"The following request illustrates a tool call that retrieves the HTTP headers from the [HttpContext] using the [IHttpContextAccessor].\n",
|
|
"\n",
|
|
"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",
|
|
"which illustrate how to access other parts of the [HttpContext].\n",
|
|
"\n",
|
|
"\n",
|
|
"[HttpContext]: https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httpcontext\n",
|
|
"[IHttpContextAccessor]: https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.http.ihttpcontextaccessor"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "3324ec56",
|
|
"metadata": {
|
|
"language_info": {
|
|
"name": "polyglot-notebook"
|
|
},
|
|
"polyglot_notebook": {
|
|
"kernelName": "pwsh"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{\n",
|
|
" \"result\": {\n",
|
|
" \"content\": [\n",
|
|
" {\n",
|
|
" \"type\": \"text\",\n",
|
|
" \"text\": \"[]\"\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" \"structuredContent\": {\n",
|
|
" \"result\": []\n",
|
|
" }\n",
|
|
" },\n",
|
|
" \"id\": 1,\n",
|
|
" \"jsonrpc\": \"2.0\"\n",
|
|
"}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"curl -s -X POST http://localhost:3001 `\n",
|
|
"-H \"ProtocolVersion: 2025-06-18\" `\n",
|
|
"-H \"Accept: application/json, text/event-stream\" `\n",
|
|
"-H \"Content-Type: application/json\" `\n",
|
|
"-d '{\n",
|
|
" \"jsonrpc\": \"2.0\",\n",
|
|
" \"id\": 1,\n",
|
|
" \"method\": \"tools/call\",\n",
|
|
" \"params\": {\n",
|
|
" \"name\": \"get_user_claims\"\n",
|
|
" }\n",
|
|
"}' | Where-Object { $_ -like \"data:*\" } | ForEach-Object { $_.Substring(5) } | jq"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".NET (C#)",
|
|
"language": "C#",
|
|
"name": ".net-csharp"
|
|
},
|
|
"language_info": {
|
|
"name": "polyglot-notebook"
|
|
},
|
|
"polyglot_notebook": {
|
|
"kernelInfo": {
|
|
"defaultKernelName": "csharp",
|
|
"items": [
|
|
{
|
|
"aliases": [],
|
|
"languageName": "csharp",
|
|
"name": "csharp"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|