- افزودن xAiMcpServer به .gitmodules بهعنوان submodule جدید.
- افزودن پروژه و pointer مربوط به xAiMcpServer به xSaherelmWorkspace.sln و root. - بهروزرسانی .vscode/launch.json و .vscode/tasks.json برای ساختار جدید. - بهروزرسانی Documents/Resources/Commands/AiApi.txtx برای تولید context مربوط به xAiMcpServer در کنار xAiApi، xAiModels و xAiService. - حذف contextهای قدیمی xDashboard-xAiApi/xAiModels/xAiService مربوط به 20261102 و ایجاد contextهای جدید 20261104 برای xAiApi، xAiMcpServer، xAiModels و xAiService.
This commit is contained in:
+3
-1
@@ -102,10 +102,12 @@
|
||||
[submodule "xAiApi"]
|
||||
path = xAiApi
|
||||
url = https://git.saherelm.ir/saherelm/xSaherElmAiApi.git
|
||||
[submodule "xAiMcpServer"]
|
||||
path = xAiMcpServer
|
||||
url = https://git.saherelm.ir/saherelm/xAiMcpServer.git
|
||||
[submodule "xApi"]
|
||||
path = xApi
|
||||
url = https://git.saherelm.ir/saherelm/xSaherElmApi.git
|
||||
[submodule "xFrameworkTest"]
|
||||
path = xFrameworkTest
|
||||
url = https://git.saherelm.ir/saherelm/xFrameworkTest.git
|
||||
|
||||
|
||||
Vendored
+20
@@ -61,6 +61,26 @@
|
||||
"/Views": "${workspaceFolder}/Views"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "xAiMcpServer",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "buildAiMcpServer",
|
||||
"program": "${workspaceFolder}/xAiMcpServer/bin/Debug/netcoreapp3.1/xAiMcpServer.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/xAiMcpServer",
|
||||
"stopAtEntry": false,
|
||||
"serverReadyAction": {
|
||||
"action": "openExternally",
|
||||
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
|
||||
},
|
||||
"env": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/Views": "${workspaceFolder}/Views"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "xClient",
|
||||
"request": "launch",
|
||||
|
||||
Vendored
+14
-2
@@ -13,6 +13,18 @@
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildIds",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/xIds/xIds.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildAiApi",
|
||||
"command": "dotnet",
|
||||
@@ -26,12 +38,12 @@
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "buildIds",
|
||||
"label": "buildAiMcpServer",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/xIds/xIds.csproj",
|
||||
"${workspaceFolder}/xAiMcpServer/xAiMcpServer.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>گزارش تغییرات ۱۴۰۵/۰۸/۱۳ - v01 | xSaherelmWorkspace</title>
|
||||
<style>
|
||||
:root{--p:#173b78;--a:#2563eb;--bg:#f4f7fb;--l:#dbe3ef;--w:#b45309}*{box-sizing:border-box}body{margin:0;padding:24px;background:linear-gradient(135deg,#eef4ff,#f8fafc);color:#172033;font-family:Tahoma,"Segoe UI",sans-serif;line-height:1.9}.wrap{max-width:1150px;margin:auto;background:#fff;border-radius:16px;box-shadow:0 12px 40px #20386422;overflow:hidden}.hero{padding:34px;background:linear-gradient(135deg,var(--p),var(--a));color:#fff}.hero h1{margin:0 0 8px}.meta{display:flex;gap:24px;flex-wrap:wrap;padding:14px 28px;background:#f8fafc;border-bottom:1px solid var(--l);color:#53627a}.meta strong{color:var(--p)}main{padding:28px}.section{margin-bottom:22px;padding:20px;background:var(--bg);border-right:5px solid var(--a);border-radius:10px}.section h2{margin:0 0 12px;color:var(--p);border-bottom:1px solid var(--l);padding-bottom:7px}table{width:100%;border-collapse:collapse;background:#fff;margin:12px 0}th,td{text-align:right;vertical-align:top;padding:9px 11px;border-bottom:1px solid var(--l)}th{background:var(--p);color:#fff}code{direction:ltr;display:inline-block;background:#e7edf6;border-radius:4px;padding:0 5px;font-family:Consolas,monospace;font-size:.9em}.note,.warn{padding:12px 15px;border-radius:7px;margin-top:12px}.note{background:#eff6ff;border-right:4px solid var(--a)}.warn{background:#fff7ed;border-right:4px solid var(--w)}footer{text-align:center;color:#68758a;padding:16px;border-top:1px solid var(--l)}
|
||||
</style></head><body><div class="wrap">
|
||||
<header class="hero"><h1>گزارش تغییرات ساختار پروژه</h1><p>xSaherelmWorkspace — بررسی وضعیت کاری Git و زیرماژولها</p></header>
|
||||
<div class="meta"><span><strong>تاریخ:</strong> ۱۴۰۵/۰۸/۱۳ (2026-11-04)</span><span><strong>نسخه:</strong> v01</span><span><strong>شاخه:</strong> master</span><span><strong>وضعیت:</strong> هنوز commit نشده</span></div><main>
|
||||
<section class="section"><h2>۱. خلاصه اجرایی</h2><p>محور اصلی تغییرات، اضافهشدن و توسعهٔ پشتیبانی MCP است. تغییرات در ریشهٔ workspace، زیرماژول مدلها، سرویس AI و پروژهٔ مستقل <code>xAiMcpServer</code> توزیع شدهاند.</p><div class="note"><strong>مبنای گزارش:</strong> git status، diffهای staged/unstaged، تاریخچهٔ زیرماژولها، مستندات توسعه و contextهای تولیدشدهٔ 2026-11-04. این گزارش وضعیت کاری است و commit نهایی محسوب نمیشود.</div></section>
|
||||
<section class="section"><h2>۲. تغییرات ریشهٔ Workspace</h2><table><thead><tr><th>بخش</th><th>شرح</th></tr></thead><tbody><tr><td>زیرماژول</td><td>ثبت <code>xAiMcpServer</code> در <code>.gitmodules</code> و اضافهشدن pointer آن به root؛ URL: <code>https://git.saherelm.ir/saherelm/xAiMcpServer.git</code></td></tr><tr><td>Solution</td><td>افزودن پروژهٔ xAiMcpServer به <code>xSaherelmWorkspace.sln</code>.</td></tr><tr><td>VS Code</td><td>بهروزرسانی <code>.vscode/launch.json</code> و <code>.vscode/tasks.json</code>.</td></tr><tr><td>Context Generator</td><td>افزودن xAiMcpServer به <code>Documents/Resources/Commands/AiApi.txtx</code>.</td></tr><tr><td>Generated Context</td><td>حذف contextهای 20261102 و ایجاد contextهای 20261104 برای xAiApi، xAiMcpServer، xAiModels و xAiService.</td></tr></tbody></table></section>
|
||||
<section class="section"><h2>۳. تغییرات MCP در زیرماژولها</h2><ul><li><strong>Modules/xAiModels:</strong> افزودن XAiMcpServer، DTO، repository/provider، seeder، enricher، Entity Framework، GraphQL و <code>XAiMcpToolDescriptor</code>.</li><li><strong>Modules/xAiService:</strong> افزودن <code>XAiMcpControllerBase</code>، <code>IXAiMcpHandler</code>، handler و DI extension.</li><li><strong>xAiMcpServer:</strong> API مستقل شامل McpController، StartupController، DI، <code>XEchoTools</code> و تنظیمات ASP.NET Core.</li><li><strong>Modules/xIdentityService:</strong> اصلاح DI برای هماهنگی ثبت وابستگیهای جدید.</li></ul></section>
|
||||
<section class="section"><h2>۴. مستندات و فایلهای جدید</h2><p>نه فایل HTML در <code>Documents/Docs/Developer</code> دربارهٔ MCP، JSON-RPC، HTTP Transport و Authentication/Authorization ایجاد شدهاند. چهار context جدید نیز در <code>Documents/GeneratedContext</code> ثبت شدهاند.</p><div class="warn"><strong>توجه:</strong> پوشههای build مانند bin و obj در بررسی محلی دیده شدند؛ این گزارش آنها را تغییر کاربردی معرفی نمیکند.</div></section>
|
||||
<section class="section"><h2>۵. وضعیت و اعتبارسنجی</h2><table><thead><tr><th>مورد</th><th>نتیجه</th></tr></thead><tbody><tr><td>staged root</td><td>تأیید شد</td></tr><tr><td>unstaged و untracked</td><td>تأیید شد</td></tr><tr><td>وضعیت داخلی submoduleها</td><td>بررسی شد</td></tr><tr><td>build/end-to-end</td><td>اجرا نشده؛ قبل از commit نهایی اجرا شود.</td></tr></tbody></table></section>
|
||||
<section class="section"><h2>۶. پیشنهاد قبل از commit</h2><ol><li>فایلهای موقت و build را از تغییرات نهایی جدا کنید.</li><li>تغییرات داخلی هر submodule را جداگانه بررسی و commit کنید، سپس pointer root را بهروزرسانی نمایید.</li><li>build و endpointهای MCP/JSON-RPC را تست کنید.</li><li>برای تغییرات بعدی از <code>v02</code> استفاده کنید.</li></ol></section>
|
||||
</main><footer>فایل بعدی: <code>1405-08-13-v02.html</code> و <code>CommitMessage-1405-08-13-v02.txt</code></footer></div></body></html>
|
||||
@@ -0,0 +1,65 @@
|
||||
================================================================================
|
||||
Commit Message - xSaherelmWorkspace
|
||||
تاریخ: ۱۴۰۵/۰۸/۱۳ (2026-11-04)
|
||||
نسخه مستند: v01
|
||||
گزارش کامل: Documents/Docs/ChangeLogs/1405-08-13-v01.html
|
||||
================================================================================
|
||||
|
||||
هدف: افزودن و یکپارچهسازی زیرساخت MCP در workspace، شامل پروژهٔ xAiMcpServer،
|
||||
مدلها و سرویسهای MCP، تنظیمات اجرای توسعه و مستندات مرتبط.
|
||||
|
||||
وضعیت: این پیام بر اساس وضعیت کاری فعلی تهیه شده است؛ تغییرات هنوز commit نشدهاند.
|
||||
|
||||
[1] Workspace / Root
|
||||
- افزودن xAiMcpServer به .gitmodules بهعنوان submodule جدید.
|
||||
- افزودن پروژه و pointer مربوط به xAiMcpServer به xSaherelmWorkspace.sln و root.
|
||||
- بهروزرسانی .vscode/launch.json و .vscode/tasks.json برای ساختار جدید.
|
||||
- بهروزرسانی Documents/Resources/Commands/AiApi.txtx برای تولید context مربوط به
|
||||
xAiMcpServer در کنار xAiApi، xAiModels و xAiService.
|
||||
- حذف contextهای قدیمی xDashboard-xAiApi/xAiModels/xAiService مربوط به 20261102 و
|
||||
ایجاد contextهای جدید 20261104 برای xAiApi، xAiMcpServer، xAiModels و xAiService.
|
||||
|
||||
[2] Modules/xAiModels
|
||||
Add MCP Server Domain and Persistence Contracts
|
||||
- افزودن XAiMcpServer و XAiMcpServerDto.
|
||||
- افزودن قراردادها و providerهای repository، in-memory/EF/Mongo، key generator،
|
||||
seeder، enricher و service provider.
|
||||
- افزودن Entity Framework configuration، mapper و GraphQL type/query/schema.
|
||||
- افزودن XAiMcpServerUsageScope و XAiMcpToolDescriptor.
|
||||
|
||||
[3] Modules/xAiService
|
||||
Add MCP Handler Integration
|
||||
- افزودن XAiMcpControllerBase.
|
||||
- افزودن IXAiMcpHandler و پیادهسازی XAiMcpHandler.
|
||||
- افزودن DI extensionهای لازم برای ثبت handler و تغییر فایل پروژهٔ سرویس.
|
||||
|
||||
[4] Modules/xIdentityService
|
||||
- اصلاح DI/XDIHelperExtension.cs برای هماهنگی ثبت وابستگیهای جدید.
|
||||
|
||||
[5] xAiMcpServer
|
||||
Add Standalone MCP ASP.NET Core Server
|
||||
- تکمیل Program و Startup و ثبت سرویسهای پایه، configuration، CORS، Swagger و
|
||||
احراز هویت/مجوز.
|
||||
- افزودن McpController و StartupController.
|
||||
- افزودن DI و ابزار XEchoTools.
|
||||
- بهروزرسانی appsettings، launchSettings و xAiMcpServer.csproj.
|
||||
- حذف appsettings.Development.json از وضعیت کاری فعلی.
|
||||
|
||||
[6] Documentation
|
||||
- افزودن مستندات HTML دربارهٔ توسعهٔ MCP Server، JSON-RPC، HTTP Transport و
|
||||
Authentication/Authorization در Documents/Docs/Developer.
|
||||
- ثبت این گزارش تغییرات و پیام commit در Documents/Docs/ChangeLogs.
|
||||
|
||||
Validation:
|
||||
- git status، diffهای staged/unstaged، وضعیت داخلی submoduleها و contextهای تولیدشده
|
||||
بررسی شد.
|
||||
- build و تست end-to-end در این مرحله اجرا نشده است.
|
||||
|
||||
Suggested commit title:
|
||||
Add MCP Server Infrastructure, Models, Handler, and Workspace Integration
|
||||
(۱۴۰۵/۰۸/۱۳ v01)
|
||||
|
||||
برای مستندسازی تغییرات بعدی، شماره نسخه را افزایش دهید:
|
||||
1405-08-13-v02.html
|
||||
CommitMessage-1405-08-13-v02.txt
|
||||
================================================================================
|
||||
+1018
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,733 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1) — نسخه اصلاحشده</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||
|
||||
:root {
|
||||
--primary: #1a365d;
|
||||
--primary-light: #2c5282;
|
||||
--accent: #c9a961;
|
||||
--accent-dark: #a8893f;
|
||||
--bg: #faf9f6;
|
||||
--card-bg: #ffffff;
|
||||
--text: #1a202c;
|
||||
--text-muted: #4a5568;
|
||||
--border: #e2e8f0;
|
||||
--success: #38a169;
|
||||
--danger: #e53e3e;
|
||||
--warning: #dd6b20;
|
||||
--code-bg: #1e293b;
|
||||
--code-text: #e2e8f0;
|
||||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.9;
|
||||
font-size: 15px;
|
||||
padding: 30px 15px;
|
||||
}
|
||||
|
||||
.document-container {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
background: var(--card-bg);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.document-header {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||||
color: white;
|
||||
padding: 50px 40px 40px;
|
||||
position: relative;
|
||||
border-bottom: 4px solid var(--accent);
|
||||
}
|
||||
|
||||
.document-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; right: 0;
|
||||
width: 200px; height: 200px;
|
||||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||||
|
||||
.company-logo {
|
||||
width: 60px; height: 60px;
|
||||
background: var(--accent);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||||
.doc-meta div { margin-bottom: 3px; }
|
||||
|
||||
.document-title {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.document-title .label {
|
||||
display: inline-block;
|
||||
background: rgba(201,169,97,0.2);
|
||||
color: var(--accent);
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid rgba(201,169,97,0.4);
|
||||
}
|
||||
|
||||
.document-title h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.document-title h2 { font-size: 15px; font-weight: 400; opacity: 0.9; }
|
||||
|
||||
.document-body { padding: 40px; }
|
||||
|
||||
.intro-text {
|
||||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 20px 25px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 35px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section { margin-bottom: 45px; page-break-inside: avoid; }
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-number {
|
||||
width: 50px; height: 50px;
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||||
}
|
||||
|
||||
.section-title { flex: 1; }
|
||||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; direction: ltr; text-align: right; }
|
||||
|
||||
.section-content { padding-right: 10px; }
|
||||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||||
.section-content p.no-indent { text-indent: 0; }
|
||||
|
||||
.highlight-box, .info-box, .success-box, .warning-box, .danger-box {
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.highlight-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #f6e05e;
|
||||
border-right: 4px solid var(--accent);
|
||||
}
|
||||
.highlight-box strong { color: var(--accent-dark); }
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||||
border: 1px solid #90cdf4;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.success-box {
|
||||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||||
border: 1px solid #9ae6b4;
|
||||
border-right: 4px solid var(--success);
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #fbd38d;
|
||||
border-right: 4px solid var(--warning);
|
||||
}
|
||||
|
||||
.danger-box {
|
||||
background: linear-gradient(to left, #fff5f5, #fed7d7);
|
||||
border: 1px solid #fc8181;
|
||||
border-right: 4px solid var(--danger);
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--code-bg);
|
||||
color: var(--code-text);
|
||||
padding: 20px 22px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
border: 1px solid #334155;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
pre::before {
|
||||
content: attr(data-lang);
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 12px;
|
||||
font-size: 10px;
|
||||
color: #64748b;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
background: #f1f5f9;
|
||||
color: #1e293b;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
pre code { background: none; color: inherit; padding: 0; display: inline; }
|
||||
|
||||
.file-path {
|
||||
background: #2c5282;
|
||||
color: #bee3f8;
|
||||
padding: 8px 14px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
margin-bottom: -15px;
|
||||
border-bottom: 2px solid #1a365d;
|
||||
}
|
||||
|
||||
.file-path::before { content: '📄 '; margin-left: 4px; }
|
||||
|
||||
.styled-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.styled-table thead {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
}
|
||||
|
||||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||||
|
||||
.file-tree {
|
||||
background: #f8fafc;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 20px 25px;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
line-height: 1.9;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.file-tree .folder { color: var(--primary); font-weight: 600; }
|
||||
.file-tree .new { color: var(--success); }
|
||||
.file-tree .modify { color: var(--warning); }
|
||||
|
||||
.checklist { list-style: none; padding: 0; margin: 15px 0; }
|
||||
.checklist li {
|
||||
padding: 10px 15px;
|
||||
background: #f8fafc;
|
||||
border-right: 3px solid var(--primary-light);
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.checklist li::before {
|
||||
content: '✓';
|
||||
color: var(--success);
|
||||
font-weight: 700;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.conclusion-box {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
margin: 30px 0;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||||
}
|
||||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||||
|
||||
.document-footer {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 25px 40px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||||
|
||||
@media print { body { background: white; padding: 0; } .document-container { box-shadow: none; border-radius: 0; } .section { page-break-inside: avoid; } }
|
||||
@media (max-width: 768px) { .document-body { padding: 25px 20px; } .document-header { padding: 30px 20px; } .header-top { flex-direction: column; gap: 15px; } .doc-meta { text-align: center; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="document-container">
|
||||
|
||||
<header class="document-header">
|
||||
<div class="header-top">
|
||||
<div class="company-badge"><div class="company-logo"></div></div>
|
||||
<div class="doc-meta">
|
||||
<div>شماره مستند: ARCH-MCP-HTTP-1405-001-R1</div>
|
||||
<div>نسخه: ۱.۱ (اصلاحشده)</div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||||
<div>طبقهبندی: فنی-داخلی</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="document-title">
|
||||
<span class="label">TECHNICAL DESIGN DOCUMENT — REVISED</span>
|
||||
<h1>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1)</h1>
|
||||
<h2>راهحل اصلاحشده با Grapevine.Extensions.Mcp — رفع خطای IServerTransport</h2>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="document-body">
|
||||
|
||||
<div class="intro-text">
|
||||
<strong>هدف مستند (نسخه اصلاحشده):</strong><br>
|
||||
این نسخه از مستند، پس از بروز خطای <code>IServerTransport</code> و تأیید حذف این اینترفیس از نسخههای جدید MCP C# SDK، بازنویسی شده است. راهحل جدید بر پایه <strong>Grapevine.Extensions.Mcp</strong> استوار است که تنها گزینه سازگار با <code>netcoreapp3.1</code> و HTTP Transport محسوب میشود.
|
||||
</div>
|
||||
|
||||
<!-- SECTION 0: Architecture Overview -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۰</div>
|
||||
<div class="section-title">
|
||||
<h3>نمای کلی معماری و جریان اتصال</h3>
|
||||
<div class="subtitle">Architecture Overview</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>جریان اتصال بین <code>xAiApi</code> و <code>xAiMcpServer</code> بدون تغییر باقی میماند. تنها تفاوت در پیادهسازی سمت سرور است که از Grapevine بهجای ASP.NET Core Pipeline استفاده میکند.</p>
|
||||
|
||||
<pre data-lang="flow">
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ xAiApi (netcoreapp3.1) │
|
||||
│ ┌───────────────────────────────────────────────────────────┐ │
|
||||
│ │ XAiMcpServerProvider │ │
|
||||
│ │ ├─ McpClient.CreateAsync(HttpClientTransport) │ │
|
||||
│ │ └─ دریافت Tools از طریق tools/list │ │
|
||||
│ └───────────────────────────────────────────────────────────┘ │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ Endpoint: http://localhost:5000/mcp │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ xAiMcpServer (netcoreapp3.1) │
|
||||
│ ┌───────────────────────────────────────────────────────────┐ │
|
||||
│ │ Grapevine RestServer │ │
|
||||
│ │ ├─ Grapevine.Extensions.Mcp │ │
|
||||
│ │ │ ├─ WithHttpTransport() │ │
|
||||
│ │ │ └─ WithToolsFromAssembly() │ │
|
||||
│ │ └─ Tools: [McpServerToolType] │ │
|
||||
│ └───────────────────────────────────────────────────────────┘ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
</pre>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>💡 نکته کلیدی:</strong> Grapevine یک فریمورک REST سبک و مستقل است که نیازی به ASP.NET Core ندارد. بسته <code>Grapevine.Extensions.Mcp</code> پلی بین Grapevine و MCP SDK ایجاد میکند و <code>WithHttpTransport()</code> را در اختیار قرار میدهد.
|
||||
</div>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">ساختار فایلهای جدید/تغییر یافته:</h4>
|
||||
<div class="file-tree">
|
||||
<span class="folder">xSaherelmWorkspace/</span>
|
||||
├── <span class="folder">xAiMcpServer/</span>
|
||||
│ ├── <span class="modify">Program.cs</span> [MODIFY — بازنویسی کامل]
|
||||
│ ├── <span class="modify">xAiMcpServer.csproj</span> [MODIFY — افزودن بسته Grapevine]
|
||||
│ ├── <span class="folder">Tools/</span>
|
||||
│ │ └── <span class="new">EchoTool.cs</span> [NEW]
|
||||
│ └── <span class="delete">Startup.cs (حذف یا غیرفعال)</span> [REMOVE — دیگر استفاده نمیشود]
|
||||
│
|
||||
├── <span class="folder">xAiApi/</span>
|
||||
│ └── <span class="modify">appsettings.json</span> [MODIFY — ثبت رکورد MCP]
|
||||
└── <span class="folder">xAiModels/</span>
|
||||
└── <span class="modify">Models/Entities/XAiMcpServer.cs</span> [NO CHANGE]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 1: Root Cause -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱</div>
|
||||
<div class="section-title">
|
||||
<h3>ریشهیابی خطای <code>IServerTransport</code></h3>
|
||||
<div class="subtitle">Root Cause Analysis</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>خطای <code>The type or namespace name 'IServerTransport' could not be found</code> ناشی از تغییرات اساسی در MCP C# SDK است. تیم توسعه SDK، اینترفیس <code>IServerTransport</code> را در نسخه v0.1.0-preview.4 حذف کرده و بهجای آن، بسته <code>ModelContextProtocol.AspNetCore</code> را معرفی کرده است[reference:3][reference:4].</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>نسخه SDK</th>
|
||||
<th>وضعیت <code>IServerTransport</code></th>
|
||||
<th>روش HTTP Transport</th>
|
||||
<th>سازگاری با netcoreapp3.1</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>v0.1.0-preview.3 و قبلتر</td>
|
||||
<td style="color: var(--success);">✓ موجود</td>
|
||||
<td>Custom Transport (پیادهسازی دستی)</td>
|
||||
<td style="color: var(--success);">✓ بله</td>
|
||||
</tr>
|
||||
<tr class="highlight-row">
|
||||
<td>v0.1.0-preview.4 و بعدتر</td>
|
||||
<td style="color: var(--danger);">✗ حذف شده</td>
|
||||
<td><code>WithHttpTransport()</code> در بسته AspNetCore</td>
|
||||
<td style="color: var(--danger);">✗ فقط .NET 8+</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>راهحل جایگزین (Grapevine)</td>
|
||||
<td>—</td>
|
||||
<td><code>WithHttpTransport()</code> در بسته Grapevine</td>
|
||||
<td style="color: var(--success); font-weight: 700;">✓ بله (netcoreapp3.1)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="danger-box">
|
||||
<strong>⚠️ نتیجه:</strong> رویکرد «Custom Transport» که در نسخه قبلی این سند توضیح داده شد، با نسخههای فعلی SDK (v0.1.0-preview.4 به بعد) منسوخ شده است. برای حفظ <code>netcoreapp3.1</code>، باید از <strong>Grapevine.Extensions.Mcp</strong> استفاده کنید.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 2: Solution with Grapevine -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۲</div>
|
||||
<div class="section-title">
|
||||
<h3>راهحل: پیادهسازی با Grapevine.Extensions.Mcp</h3>
|
||||
<div class="subtitle">Solution: Grapevine.Extensions.Mcp</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>بسته <code>Grapevine.Extensions.Mcp</code> نسخه 5.0.2 بهصراحت از <code>netcoreapp3.1</code> پشتیبانی میکند[reference:5]. در ادامه، مراحل پیادهسازی گامبهگام آورده شده است.</p>
|
||||
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">گام ۲.۱ — نصب بستههای NuGet</h4>
|
||||
<p>در فایل <code>xAiMcpServer.csproj</code>:</p>
|
||||
<pre data-lang="xml"><code><ItemGroup>
|
||||
<PackageReference Include="Grapevine.Extensions.Mcp" Version="5.0.2" />
|
||||
<PackageReference Include="ModelContextProtocol" Version="*" />
|
||||
</ItemGroup></code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲.۲ — تعریف Tool نمونه</h4>
|
||||
<div class="file-path">Tools/EchoTool.cs</div>
|
||||
<pre data-lang="csharp"><code>using System.ComponentModel;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer.Tools
|
||||
{
|
||||
[McpServerToolType]
|
||||
public static class EchoTool
|
||||
{
|
||||
[McpServerTool, Description("Echoes the message back to the client.")]
|
||||
public static string Echo(string message) => $"hello {message}";
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲.۳ — بازنویسی <code>Program.cs</code></h4>
|
||||
<p>فایل <code>Program.cs</code> موجود را حذف کرده و با کد زیر جایگزین کنید:</p>
|
||||
|
||||
<div class="file-path">Program.cs</div>
|
||||
<pre data-lang="csharp"><code>using System;
|
||||
using Grapevine;
|
||||
using Grapevine.Extensions.Mcp;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = new RestServerBuilder(
|
||||
services => services
|
||||
.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithToolsFromAssembly(),
|
||||
server =>
|
||||
{
|
||||
server.Prefixes.Add("http://localhost:5000/");
|
||||
}
|
||||
);
|
||||
|
||||
var server = builder.Build();
|
||||
server.Start();
|
||||
|
||||
Console.WriteLine("MCP Server (Grapevine) running on http://localhost:5000/mcp");
|
||||
Console.WriteLine("Press Enter to stop...");
|
||||
Console.ReadLine();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>💡 نکته:</strong> Grapevine یک سرور HTTP مستقل است و دیگر از <code>Startup.cs</code> و Pipeline ASP.NET Core استفاده نمیشود. اگر به Middlewareهای موجود (مانند <code>xIdentityService</code>) نیاز دارید، باید آنها را در سطح Grapevine پیادهسازی کنید یا از Reverse Proxy استفاده نمایید.
|
||||
</div>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲.۴ — حذف یا غیرفعالسازی <code>Startup.cs</code></h4>
|
||||
<p>از آنجا که Grapevine مستقل از ASP.NET Core است، دیگر نیازی به <code>Startup.cs</code> و <code>ConfigureServices</code> نیست. میتوانید فایل <code>Startup.cs</code> را حذف کنید یا آن را بدون استفاده رها کنید (در حالت دوم، مطمئن شوید که <code>Program.cs</code> دیگر به آن ارجاع نمیدهد).</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 3: Connecting xAiApi -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۳</div>
|
||||
<div class="section-title">
|
||||
<h3>اتصال <code>xAiApi</code> به MCP Server</h3>
|
||||
<div class="subtitle">Connecting xAiApi</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>پس از اجرای <code>xAiMcpServer</code> با Grapevine، باید یک رکورد <code>XAiMcpServer</code> در دیتابیس <code>xAiApi</code> ثبت کنید تا <code>XAiMcpServerProvider</code> بتواند به آن متصل شود.</p>
|
||||
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">گام ۳.۱ — ثبت رکورد از طریق API</h4>
|
||||
<pre data-lang="json"><code>POST /McpServer
|
||||
{
|
||||
"name": "xAiMcpServer-Tools",
|
||||
"endpoint": "http://localhost:5000/mcp",
|
||||
"enabled": true,
|
||||
"scope": "Owner",
|
||||
"timeoutSeconds": 30,
|
||||
"description": "ابزارهای سازمانی از xAiMcpServer (Grapevine)"
|
||||
}</code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۳.۲ — تأیید اتصال</h4>
|
||||
<p>متد <code>GetAvailableToolsAsync</code> را در <code>XAiMcpServerProvider</code> فراخوانی کنید. اگر Toolهای <code>Echo</code> در خروجی ظاهر شدند، اتصال کامل است.</p>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✓ نتیجه:</strong> <code>xAiApi</code> اکنون میتواند ابزارهای <code>xAiMcpServer</code> را کشف کرده و در اختیار موتور ایجنت قرار دهد.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 4: Security & Limitations -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۴</div>
|
||||
<div class="section-title">
|
||||
<h3>محدودیتها و ملاحظات امنیتی</h3>
|
||||
<div class="subtitle">Limitations & Security</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>روش Grapevine در مقایسه با ASP.NET Core، چند محدودیت دارد که باید در نظر گرفته شود:</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ویژگی</th>
|
||||
<th>ASP.NET Core (net8.0+)</th>
|
||||
<th>Grapevine (netcoreapp3.1)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Middlewareهای موجود (<code>xIdentityService</code>)</td>
|
||||
<td style="color: var(--success);">✓ کامل</td>
|
||||
<td style="color: var(--danger);">✗ باید دستی پیادهسازی شود</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Swagger / OpenAPI</td>
|
||||
<td style="color: var(--success);">✓ کامل</td>
|
||||
<td style="color: var(--warning);">⚠ محدود</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>پشتیبانی رسمی MCP SDK</td>
|
||||
<td style="color: var(--success);">✓ رسمی</td>
|
||||
<td style="color: var(--warning);">⚠ غیررسمی (Community)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>پایداری بلندمدت</td>
|
||||
<td style="color: var(--success);">✓ بالا</td>
|
||||
<td style="color: var(--warning);">⚠ متوسط (وابسته به جامعه)</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="warning-box">
|
||||
<strong>⚠️ توصیه امنیتی:</strong> اگر <code>xAiMcpServer</code> در محیط عملیاتی حساس اجرا میشود، حتماً آن را پشت یک Reverse Proxy (مانند Nginx) قرار دهید و احراز هویت (مانند <code>X-Api-Key</code>) را در سطح Proxy اعمال کنید. سپس در رکورد <code>XAiMcpServer</code> در <code>xAiApi</code>، هدر مربوطه را تنظیم نمایید.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 5: Troubleshooting -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۵</div>
|
||||
<div class="section-title">
|
||||
<h3>عیبیابی خطاهای رایج (پس از اصلاح)</h3>
|
||||
<div class="subtitle">Troubleshooting</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>علامت</th>
|
||||
<th>علت احتمالی</th>
|
||||
<th>راهحل</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>404</code> روی <code>/mcp</code></td>
|
||||
<td>مسیر Grapevine بهدرستی تنظیم نشده</td>
|
||||
<td>مطمئن شوید <code>WithHttpTransport()</code> مسیر <code>/mcp</code> را بهصورت پیشفرض فعال میکند</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>401 Unauthorized</code></td>
|
||||
<td>احراز هویت در سطح Grapevine پیادهسازی نشده</td>
|
||||
<td>از Reverse Proxy با <code>X-Api-Key</code> استفاده کنید یا احراز هویت را دستی اضافه نمایید</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>NullReferenceException</code> هنگام فراخوانی Tool</td>
|
||||
<td>Tools بهدرستی اسکن نشدهاند</td>
|
||||
<td>مطمئن شوید <code>WithToolsFromAssembly()</code> فراخوانی شده و کلاس Tool دارای <code>[McpServerToolType]</code> است</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>xAiApi</code> به Tools دسترسی ندارد</td>
|
||||
<td>رکورد <code>XAiMcpServer</code> ثبت نشده یا <code>Enabled = false</code> است</td>
|
||||
<td>رکورد را با <code>Enabled = true</code> و <code>Endpoint</code> صحیح ثبت کنید</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 6: Summary -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۶</div>
|
||||
<div class="section-title">
|
||||
<h3>جمعبندی و چکلیست نهایی</h3>
|
||||
<div class="subtitle">Summary & Checklist</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>با اعمال این اصلاحات، خطای <code>IServerTransport</code> برطرف شده و <code>xAiMcpServer</code> با حفظ <code>netcoreapp3.1</code>، یک MCP Server با HTTP Transport خواهد بود.</p>
|
||||
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">چکلیست فایلهای جدید/تغییر یافته:</h4>
|
||||
<ul class="checklist">
|
||||
<li>افزودن بسته <code>Grapevine.Extensions.Mcp</code> (نسخه 5.0.2) به <code>xAiMcpServer.csproj</code></li>
|
||||
<li>ایجاد <code>Tools/EchoTool.cs</code> با <code>[McpServerToolType]</code> و <code>[McpServerTool]</code></li>
|
||||
<li>بازنویسی <code>Program.cs</code> با استفاده از <code>RestServerBuilder</code> و <code>WithHttpTransport()</code></li>
|
||||
<li>حذف یا غیرفعالسازی <code>Startup.cs</code> (دیگر استفاده نمیشود)</li>
|
||||
<li>ثبت رکورد <code>XAiMcpServer</code> در <code>xAiApi</code> با Endpoint <code>http://localhost:5000/mcp</code></li>
|
||||
<li>تست اتصال از طریق <code>GetAvailableToolsAsync</code></li>
|
||||
</ul>
|
||||
|
||||
<div class="conclusion-box">
|
||||
<h3>🎯 نتیجه نهایی</h3>
|
||||
<p>خطای <code>IServerTransport</code> با جایگزینی رویکرد Custom Transport با <code>Grapevine.Extensions.Mcp</code> برطرف شد.</p>
|
||||
<p>اکنون <code>xAiMcpServer</code> با حفظ <code>netcoreapp3.1</code>، یک MCP Server فعال با HTTP Transport است و <code>xAiApi</code> میتواند ابزارهای آن را در اختیار موتور ایجنت قرار دهد.</p>
|
||||
<div class="highlight" style="background: rgba(201,169,97,0.2); padding: 15px; border-radius: 8px; margin-top: 20px; border: 1px solid rgba(201,169,97,0.4);">
|
||||
<strong>💎 ارزش پیشنهادی:</strong><br>
|
||||
حفظ <code>netcoreapp3.1</code> + رفع خطای <code>IServerTransport</code> + پیادهسازی سریع MCP + اتصال کامل به <code>xAiApi</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>📞 گام بعدی:</strong> یک Tool واقعی (مانند <code>SearchKnowledge</code> یا <code>GetProjectInfo</code>) را در <code>xAiMcpServer</code> پیادهسازی کنید و از طریق <code>xAiApi</code> فراخوانی نمایید تا زنجیره کامل (Agent → MCP Client → MCP Server → Tool) تأیید شود.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-info" style="text-align: center; padding: 15px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 30px;">
|
||||
این مستند محرمانه بوده و صرفاً جهت استفاده تیم توسعه xSaherelmWorkspace تهیه شده است.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="document-footer">
|
||||
<div class="footer-brand">طراحی و مستندسازی: تیم معماری xSaherelmWorkspace</div>
|
||||
<div class="footer-divider"></div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۱ (اصلاحشده) | طبقهبندی: فنی-داخلی</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,573 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1) — نسخه ۱.۳</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||
|
||||
:root {
|
||||
--primary: #1a365d;
|
||||
--primary-light: #2c5282;
|
||||
--accent: #c9a961;
|
||||
--accent-dark: #a8893f;
|
||||
--bg: #faf9f6;
|
||||
--card-bg: #ffffff;
|
||||
--text: #1a202c;
|
||||
--text-muted: #4a5568;
|
||||
--border: #e2e8f0;
|
||||
--success: #38a169;
|
||||
--danger: #e53e3e;
|
||||
--warning: #dd6b20;
|
||||
--code-bg: #1e293b;
|
||||
--code-text: #e2e8f0;
|
||||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.9;
|
||||
font-size: 15px;
|
||||
padding: 30px 15px;
|
||||
}
|
||||
|
||||
.document-container {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
background: var(--card-bg);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.document-header {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||||
color: white;
|
||||
padding: 50px 40px 40px;
|
||||
position: relative;
|
||||
border-bottom: 4px solid var(--accent);
|
||||
}
|
||||
|
||||
.document-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; right: 0;
|
||||
width: 200px; height: 200px;
|
||||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||||
|
||||
.company-logo {
|
||||
width: 60px; height: 60px;
|
||||
background: var(--accent);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||||
.doc-meta div { margin-bottom: 3px; }
|
||||
|
||||
.document-title {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.document-title .label {
|
||||
display: inline-block;
|
||||
background: rgba(201,169,97,0.2);
|
||||
color: var(--accent);
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid rgba(201,169,97,0.4);
|
||||
}
|
||||
|
||||
.document-title h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.document-title h2 { font-size: 15px; font-weight: 400; opacity: 0.9; }
|
||||
|
||||
.document-body { padding: 40px; }
|
||||
|
||||
.intro-text {
|
||||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 20px 25px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 35px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section { margin-bottom: 45px; page-break-inside: avoid; }
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-number {
|
||||
width: 50px; height: 50px;
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||||
}
|
||||
|
||||
.section-title { flex: 1; }
|
||||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; direction: ltr; text-align: right; }
|
||||
|
||||
.section-content { padding-right: 10px; }
|
||||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||||
.section-content p.no-indent { text-indent: 0; }
|
||||
|
||||
.highlight-box, .info-box, .success-box, .warning-box, .danger-box {
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.highlight-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #f6e05e;
|
||||
border-right: 4px solid var(--accent);
|
||||
}
|
||||
.highlight-box strong { color: var(--accent-dark); }
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||||
border: 1px solid #90cdf4;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.success-box {
|
||||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||||
border: 1px solid #9ae6b4;
|
||||
border-right: 4px solid var(--success);
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #fbd38d;
|
||||
border-right: 4px solid var(--warning);
|
||||
}
|
||||
|
||||
.danger-box {
|
||||
background: linear-gradient(to left, #fff5f5, #fed7d7);
|
||||
border: 1px solid #fc8181;
|
||||
border-right: 4px solid var(--danger);
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--code-bg);
|
||||
color: var(--code-text);
|
||||
padding: 20px 22px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
border: 1px solid #334155;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
pre::before {
|
||||
content: attr(data-lang);
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 12px;
|
||||
font-size: 10px;
|
||||
color: #64748b;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
background: #f1f5f9;
|
||||
color: #1e293b;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
pre code { background: none; color: inherit; padding: 0; display: inline; }
|
||||
|
||||
.file-path {
|
||||
background: #2c5282;
|
||||
color: #bee3f8;
|
||||
padding: 8px 14px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
margin-bottom: -15px;
|
||||
border-bottom: 2px solid #1a365d;
|
||||
}
|
||||
|
||||
.file-path::before { content: '📄 '; margin-left: 4px; }
|
||||
|
||||
.styled-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.styled-table thead {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
}
|
||||
|
||||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||||
|
||||
.file-tree {
|
||||
background: #f8fafc;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 20px 25px;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
line-height: 1.9;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.file-tree .folder { color: var(--primary); font-weight: 600; }
|
||||
.file-tree .new { color: var(--success); }
|
||||
.file-tree .modify { color: var(--warning); }
|
||||
|
||||
.checklist { list-style: none; padding: 0; margin: 15px 0; }
|
||||
.checklist li {
|
||||
padding: 10px 15px;
|
||||
background: #f8fafc;
|
||||
border-right: 3px solid var(--primary-light);
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.checklist li::before {
|
||||
content: '✓';
|
||||
color: var(--success);
|
||||
font-weight: 700;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.conclusion-box {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
margin: 30px 0;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||||
}
|
||||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||||
|
||||
.document-footer {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 25px 40px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||||
|
||||
@media print { body { background: white; padding: 0; } .document-container { box-shadow: none; border-radius: 0; } .section { page-break-inside: avoid; } }
|
||||
@media (max-width: 768px) { .document-body { padding: 25px 20px; } .document-header { padding: 30px 20px; } .header-top { flex-direction: column; gap: 15px; } .doc-meta { text-align: center; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="document-container">
|
||||
|
||||
<header class="document-header">
|
||||
<div class="header-top">
|
||||
<div class="company-badge"><div class="company-logo"></div></div>
|
||||
<div class="doc-meta">
|
||||
<div>شماره مستند: ARCH-MCP-HTTP-1405-001-R3</div>
|
||||
<div>نسخه: ۱.۳ (اصلاحشده نهایی)</div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||||
<div>طبقهبندی: فنی-داخلی</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="document-title">
|
||||
<span class="label">TECHNICAL DESIGN DOCUMENT — FINAL R3</span>
|
||||
<h1>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1)</h1>
|
||||
<h2>رفع نهایی خطای IServiceCollection.Prefixes + فعالسازی MapMcp</h2>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="document-body">
|
||||
|
||||
<div class="intro-text">
|
||||
<strong>هدف مستند (نسخه ۱.۳ — نهایی):</strong><br>
|
||||
این نسخه پس از بروز خطای <code>'IServiceCollection' does not contain a definition for 'Prefixes'</code> بازنویسی شده است. علت خطا، استنتاج نادرست نوع پارامتر <code>server</code> توسط کامپایلر بود. با مشخص کردن صریح نوع <code>IRestServer</code> و افزودن فراخوانی <code>server.MapMcp("/mcp")</code> (مطابق مستندات رسمی)، مشکل بهطور کامل برطرف میشود.
|
||||
</div>
|
||||
|
||||
<!-- SECTION 0: Root Cause -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۰</div>
|
||||
<div class="section-title">
|
||||
<h3>ریشهیابی خطای <code>IServiceCollection.Prefixes</code></h3>
|
||||
<div class="subtitle">Root Cause: Type Inference Failure</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>خطای مشاهدهشده نشان میدهد که کامپایلر، پارامتر <code>server</code> در لامبدای دوم را بهجای <code>IRestServer</code>، از نوع <code>IServiceCollection</code> استنتاج کرده است. این اتفاق زمانی رخ میدهد که overload مناسب سازنده <code>RestServerBuilder</code> پیدا نشود یا ابهام نوعی وجود داشته باشد.</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>پارامتر</th>
|
||||
<th>نوع صحیح</th>
|
||||
<th>نوع استنتاجشده (اشتباه)</th>
|
||||
<th>نتیجه</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>اول (<code>services</code>)</td>
|
||||
<td><code>Action<IServiceCollection></code></td>
|
||||
<td><code>IServiceCollection</code></td>
|
||||
<td style="color: var(--success);">✓ صحیح</td>
|
||||
</tr>
|
||||
<tr class="highlight-row">
|
||||
<td>دوم (<code>server</code>)</td>
|
||||
<td><code>Action<IRestServer></code></td>
|
||||
<td><code>IServiceCollection</code></td>
|
||||
<td style="color: var(--danger);">✗ خطا: <code>Prefixes</code> وجود ندارد</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="danger-box">
|
||||
<strong>⚠️ راهحل:</strong> نوع پارامتر دوم را بهصورت صریح <code>(IRestServer server)</code> مشخص کنید تا کامپایلر ویژگی <code>Prefixes</code> را بشناسد. همچنین برای فعالسازی مسیر MCP، فراخوانی <code>server.MapMcp("/mcp")</code> پس از <code>Build()</code> الزامی است.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 1: Corrected Program.cs -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱</div>
|
||||
<div class="section-title">
|
||||
<h3>کد نهایی اصلاحشده <code>Program.cs</code></h3>
|
||||
<div class="subtitle">Final Corrected Program.cs</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>کد زیر، تمام موارد لازم را برای کارکرد صحیح سرور MCP فراهم میکند: نوع صریح <code>IRestServer</code>، افزودن Prefix، و فعالسازی <code>MapMcp</code>.</p>
|
||||
|
||||
<div class="file-path">Program.cs</div>
|
||||
<pre data-lang="csharp"><code>using System;
|
||||
using Grapevine;
|
||||
using Grapevine.Extensions.Mcp;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = new RestServerBuilder(
|
||||
// ۱. لامبدای اول: تنظیمات IServiceCollection
|
||||
services => services
|
||||
.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithToolsFromAssembly(),
|
||||
|
||||
// ۲. لامبدای دوم: تنظیمات IRestServer (نوع صریح)
|
||||
(IRestServer server) =>
|
||||
{
|
||||
server.Prefixes.Add("http://localhost:5000/");
|
||||
}
|
||||
);
|
||||
|
||||
var server = builder.Build();
|
||||
server.MapMcp("/mcp"); // فعالسازی مسیر MCP
|
||||
server.Start();
|
||||
|
||||
Console.WriteLine("MCP Server (Grapevine) running on http://localhost:5000/mcp");
|
||||
Console.WriteLine("Press Enter to stop...");
|
||||
Console.ReadLine();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✓ نکات کلیدی:</strong>
|
||||
<ul style="padding-right: 20px; margin-top: 10px;">
|
||||
<li><code>using Grapevine;</code> برای دسترسی به <code>IRestServer</code> ضروری است.</li>
|
||||
<li>نوع صریح <code>(IRestServer server)</code> از خطای استنتاج نوع جلوگیری میکند.</li>
|
||||
<li><code>server.MapMcp("/mcp")</code> مسیر MCP را در Grapevine ثبت میکند؛ بدون آن، درخواستهای <code>xAiApi</code> با ۴۰۴ مواجه میشوند.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 2: Remaining Steps (Summary) -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۲</div>
|
||||
<div class="section-title">
|
||||
<h3>سایر مراحل (بدون تغییر)</h3>
|
||||
<div class="subtitle">Other Steps (Unchanged)</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>بقیه مراحل (نصب بسته، تعریف Tool، حذف <code>Startup.cs</code>، ثبت رکورد در <code>xAiApi</code> و تست) همانند نسخههای قبلی است. برای کامل بودن، خلاصه آنها در ادامه آمده است:</p>
|
||||
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">گام ۲.۱ — نصب بستههای NuGet</h4>
|
||||
<pre data-lang="xml"><code><ItemGroup>
|
||||
<PackageReference Include="Grapevine.Extensions.Mcp" Version="5.0.2" />
|
||||
<PackageReference Include="ModelContextProtocol" Version="*" />
|
||||
</ItemGroup></code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲.۲ — تعریف Tool</h4>
|
||||
<div class="file-path">Tools/EchoTool.cs</div>
|
||||
<pre data-lang="csharp"><code>using System.ComponentModel;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer.Tools
|
||||
{
|
||||
[McpServerToolType]
|
||||
public static class EchoTool
|
||||
{
|
||||
[McpServerTool, Description("Echoes the message back to the client.")]
|
||||
public static string Echo(string message) => $"hello {message}";
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲.۳ — حذف یا غیرفعالسازی <code>Startup.cs</code></h4>
|
||||
<p>از آنجا که Grapevine مستقل از ASP.NET Core است، دیگر نیازی به <code>Startup.cs</code> و <code>ConfigureServices</code> نیست. میتوانید فایل <code>Startup.cs</code> را حذف کنید.</p>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۳ — اتصال <code>xAiApi</code></h4>
|
||||
<pre data-lang="json"><code>POST /McpServer
|
||||
{
|
||||
"name": "xAiMcpServer-Tools",
|
||||
"endpoint": "http://localhost:5000/mcp",
|
||||
"enabled": true,
|
||||
"scope": "Owner",
|
||||
"timeoutSeconds": 30,
|
||||
"description": "ابزارهای سازمانی از xAiMcpServer (Grapevine)"
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 3: Summary & Checklist -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۳</div>
|
||||
<div class="section-title">
|
||||
<h3>جمعبندی و چکلیست نهایی</h3>
|
||||
<div class="subtitle">Summary & Checklist</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>با اعمال دو تغییر کلیدی (نوع صریح <code>IRestServer</code> و افزودن <code>MapMcp</code>)، خطای کامپایل برطرف شده و سرور MCP با HTTP Transport روی <code>netcoreapp3.1</code> فعال میشود.</p>
|
||||
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">چکلیست نهایی:</h4>
|
||||
<ul class="checklist">
|
||||
<li>نصب بسته <code>Grapevine.Extensions.Mcp</code> (نسخه 5.0.2)</li>
|
||||
<li>تعریف <code>Tools/EchoTool.cs</code> با <code>[McpServerToolType]</code> و <code>[McpServerTool]</code></li>
|
||||
<li>بازنویسی <code>Program.cs</code> با دو لامبدای جداگانه و نوع صریح <code>(IRestServer server)</code></li>
|
||||
<li>افزودن <code>server.MapMcp("/mcp")</code> پس از <code>Build()</code></li>
|
||||
<li>حذف یا غیرفعالسازی <code>Startup.cs</code></li>
|
||||
<li>ثبت رکورد <code>XAiMcpServer</code> در <code>xAiApi</code> با Endpoint <code>http://localhost:5000/mcp</code></li>
|
||||
<li>تست اتصال از طریق <code>GetAvailableToolsAsync</code></li>
|
||||
</ul>
|
||||
|
||||
<div class="conclusion-box">
|
||||
<h3>🎯 نتیجه نهایی</h3>
|
||||
<p>خطای <code>IServiceCollection.Prefixes</code> با مشخص کردن نوع صریح <code>IRestServer</code> و فعالسازی <code>MapMcp</code> بهطور کامل برطرف شد.</p>
|
||||
<p>اکنون <code>xAiMcpServer</code> با <code>netcoreapp3.1</code> و HTTP Transport فعال است و <code>xAiApi</code> میتواند ابزارهای آن را کشف و استفاده کند.</p>
|
||||
<div class="highlight" style="background: rgba(201,169,97,0.2); padding: 15px; border-radius: 8px; margin-top: 20px; border: 1px solid rgba(201,169,97,0.4);">
|
||||
<strong>💎 ارزش پیشنهادی:</strong><br>
|
||||
حفظ <code>netcoreapp3.1</code> + رفع کامل خطای کامپایل + MCP Server فعال + اتصال کامل به <code>xAiApi</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>📞 گام بعدی:</strong> یک Tool واقعی (مانند <code>SearchKnowledge</code> یا <code>GetProjectInfo</code>) را پیادهسازی کنید و از طریق <code>xAiApi</code> فراخوانی نمایید تا زنجیره کامل (Agent → MCP Client → MCP Server → Tool) تأیید شود.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-info" style="text-align: center; padding: 15px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 30px;">
|
||||
این مستند محرمانه بوده و صرفاً جهت استفاده تیم توسعه xSaherelmWorkspace تهیه شده است.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="document-footer">
|
||||
<div class="footer-brand">طراحی و مستندسازی: تیم معماری xSaherelmWorkspace</div>
|
||||
<div class="footer-divider"></div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۳ (نهایی) | طبقهبندی: فنی-داخلی</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,566 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1) — نسخه اصلاحشده ۱.۲</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||
|
||||
:root {
|
||||
--primary: #1a365d;
|
||||
--primary-light: #2c5282;
|
||||
--accent: #c9a961;
|
||||
--accent-dark: #a8893f;
|
||||
--bg: #faf9f6;
|
||||
--card-bg: #ffffff;
|
||||
--text: #1a202c;
|
||||
--text-muted: #4a5568;
|
||||
--border: #e2e8f0;
|
||||
--success: #38a169;
|
||||
--danger: #e53e3e;
|
||||
--warning: #dd6b20;
|
||||
--code-bg: #1e293b;
|
||||
--code-text: #e2e8f0;
|
||||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.9;
|
||||
font-size: 15px;
|
||||
padding: 30px 15px;
|
||||
}
|
||||
|
||||
.document-container {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
background: var(--card-bg);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.document-header {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||||
color: white;
|
||||
padding: 50px 40px 40px;
|
||||
position: relative;
|
||||
border-bottom: 4px solid var(--accent);
|
||||
}
|
||||
|
||||
.document-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; right: 0;
|
||||
width: 200px; height: 200px;
|
||||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||||
|
||||
.company-logo {
|
||||
width: 60px; height: 60px;
|
||||
background: var(--accent);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||||
.doc-meta div { margin-bottom: 3px; }
|
||||
|
||||
.document-title {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.document-title .label {
|
||||
display: inline-block;
|
||||
background: rgba(201,169,97,0.2);
|
||||
color: var(--accent);
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid rgba(201,169,97,0.4);
|
||||
}
|
||||
|
||||
.document-title h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.document-title h2 { font-size: 15px; font-weight: 400; opacity: 0.9; }
|
||||
|
||||
.document-body { padding: 40px; }
|
||||
|
||||
.intro-text {
|
||||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 20px 25px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 35px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section { margin-bottom: 45px; page-break-inside: avoid; }
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-number {
|
||||
width: 50px; height: 50px;
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||||
}
|
||||
|
||||
.section-title { flex: 1; }
|
||||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; direction: ltr; text-align: right; }
|
||||
|
||||
.section-content { padding-right: 10px; }
|
||||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||||
.section-content p.no-indent { text-indent: 0; }
|
||||
|
||||
.highlight-box, .info-box, .success-box, .warning-box, .danger-box {
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.highlight-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #f6e05e;
|
||||
border-right: 4px solid var(--accent);
|
||||
}
|
||||
.highlight-box strong { color: var(--accent-dark); }
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||||
border: 1px solid #90cdf4;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.success-box {
|
||||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||||
border: 1px solid #9ae6b4;
|
||||
border-right: 4px solid var(--success);
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #fbd38d;
|
||||
border-right: 4px solid var(--warning);
|
||||
}
|
||||
|
||||
.danger-box {
|
||||
background: linear-gradient(to left, #fff5f5, #fed7d7);
|
||||
border: 1px solid #fc8181;
|
||||
border-right: 4px solid var(--danger);
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--code-bg);
|
||||
color: var(--code-text);
|
||||
padding: 20px 22px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
border: 1px solid #334155;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
pre::before {
|
||||
content: attr(data-lang);
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 12px;
|
||||
font-size: 10px;
|
||||
color: #64748b;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
background: #f1f5f9;
|
||||
color: #1e293b;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
pre code { background: none; color: inherit; padding: 0; display: inline; }
|
||||
|
||||
.file-path {
|
||||
background: #2c5282;
|
||||
color: #bee3f8;
|
||||
padding: 8px 14px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
margin-bottom: -15px;
|
||||
border-bottom: 2px solid #1a365d;
|
||||
}
|
||||
|
||||
.file-path::before { content: '📄 '; margin-left: 4px; }
|
||||
|
||||
.styled-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.styled-table thead {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
}
|
||||
|
||||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||||
|
||||
.file-tree {
|
||||
background: #f8fafc;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 20px 25px;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
line-height: 1.9;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.file-tree .folder { color: var(--primary); font-weight: 600; }
|
||||
.file-tree .new { color: var(--success); }
|
||||
.file-tree .modify { color: var(--warning); }
|
||||
|
||||
.checklist { list-style: none; padding: 0; margin: 15px 0; }
|
||||
.checklist li {
|
||||
padding: 10px 15px;
|
||||
background: #f8fafc;
|
||||
border-right: 3px solid var(--primary-light);
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.checklist li::before {
|
||||
content: '✓';
|
||||
color: var(--success);
|
||||
font-weight: 700;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.conclusion-box {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
margin: 30px 0;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||||
}
|
||||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||||
|
||||
.document-footer {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 25px 40px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||||
|
||||
@media print { body { background: white; padding: 0; } .document-container { box-shadow: none; border-radius: 0; } .section { page-break-inside: avoid; } }
|
||||
@media (max-width: 768px) { .document-body { padding: 25px 20px; } .document-header { padding: 30px 20px; } .header-top { flex-direction: column; gap: 15px; } .doc-meta { text-align: center; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="document-container">
|
||||
|
||||
<header class="document-header">
|
||||
<div class="header-top">
|
||||
<div class="company-badge"><div class="company-logo"></div></div>
|
||||
<div class="doc-meta">
|
||||
<div>شماره مستند: ARCH-MCP-HTTP-1405-001-R2</div>
|
||||
<div>نسخه: ۱.۲ (اصلاحشده)</div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||||
<div>طبقهبندی: فنی-داخلی</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="document-title">
|
||||
<span class="label">TECHNICAL DESIGN DOCUMENT — REVISED R2</span>
|
||||
<h1>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1)</h1>
|
||||
<h2>رفع خطای IServiceCollection.Prefixes — پیکربندی صحیح RestServerBuilder</h2>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="document-body">
|
||||
|
||||
<div class="intro-text">
|
||||
<strong>هدف مستند (نسخه ۱.۲):</strong><br>
|
||||
این نسخه پس از بروز خطای <code>'IServiceCollection' does not contain a definition for 'Prefixes'</code> بازنویسی شده است. علت خطا، استفاده نادرست از سازنده <code>RestServerBuilder</code> و ادغام دو لامبدای جداگانه (services و server) بود. در این نسخه، پیکربندی صحیح و کد نهایی اصلاحشده ارائه میشود.
|
||||
</div>
|
||||
|
||||
<!-- SECTION 0: Root Cause of New Error -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۰</div>
|
||||
<div class="section-title">
|
||||
<h3>ریشهیابی خطای <code>IServiceCollection.Prefixes</code></h3>
|
||||
<div class="subtitle">Root Cause: IServiceCollection vs RestServer</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>خطای <code>'IServiceCollection' does not contain a definition for 'Prefixes'</code> نشان میدهد که متد <code>server.Prefixes.Add(...)</code> در محل اشتباهی فراخوانی شده است. سازنده <code>RestServerBuilder</code> در بسته <code>Grapevine.Extensions.Mcp</code> دو پارامتر دارد[reference:1]:</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>پارامتر</th>
|
||||
<th>نوع</th>
|
||||
<th>کاربرد</th>
|
||||
<th>نمونه</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>پارامتر اول</strong></td>
|
||||
<td><code>Action<IServiceCollection></code></td>
|
||||
<td>ثبت سرویسهای MCP (AddMcpServer, WithHttpTransport, WithToolsFromAssembly)</td>
|
||||
<td><code>services => services.AddMcpServer()...</code></td>
|
||||
</tr>
|
||||
<tr class="highlight-row">
|
||||
<td><strong>پارامتر دوم</strong></td>
|
||||
<td><code>Action<RestServer></code></td>
|
||||
<td>پیکربندی سرور Grapevine (Prefixes, Logging, ...)</td>
|
||||
<td><code>server => server.Prefixes.Add("http://localhost:5000/")</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="danger-box">
|
||||
<strong>⚠️ علت خطا:</strong> در کد قبلی، لامبدای <code>server => server.Prefixes.Add(...)</code> بهاشتباه بهعنوان پارامتر <strong>اول</strong> (یعنی <code>services</code>) پاس داده شده بود. در حالی که <code>services</code> از نوع <code>IServiceCollection</code> است و ویژگی <code>Prefixes</code> را ندارد.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 1: Corrected Program.cs -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱</div>
|
||||
<div class="section-title">
|
||||
<h3>کد اصلاحشده <code>Program.cs</code></h3>
|
||||
<div class="subtitle">Corrected Program.cs</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>کد زیر، دو لامبدا را بهدرستی از هم جدا میکند. لامبدای اول فقط برای <code>IServiceCollection</code> و لامبدای دوم فقط برای <code>RestServer</code> است.</p>
|
||||
|
||||
<div class="file-path">Program.cs</div>
|
||||
<pre data-lang="csharp"><code>using System;
|
||||
using Grapevine;
|
||||
using Grapevine.Extensions.Mcp;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = new RestServerBuilder(
|
||||
// ۱. لامبدای اول: تنظیمات IServiceCollection (ثبت سرویسهای MCP)
|
||||
services => services
|
||||
.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithToolsFromAssembly(),
|
||||
|
||||
// ۲. لامبدای دوم: تنظیمات RestServer (تنظیم آدرس و پورت)
|
||||
server =>
|
||||
{
|
||||
server.Prefixes.Add("http://localhost:5000/");
|
||||
}
|
||||
);
|
||||
|
||||
var server = builder.Build();
|
||||
server.Start();
|
||||
|
||||
Console.WriteLine("MCP Server (Grapevine) running on http://localhost:5000/mcp");
|
||||
Console.WriteLine("Press Enter to stop...");
|
||||
Console.ReadLine();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✓ نکته کلیدی:</strong> دقت کنید که دو لامبدا با کاما از هم جدا شدهاند. پارامتر اول (<code>services</code>) هرگز نباید شامل <code>server.Prefixes</code> باشد.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 2: Full Updated Guide (Rest of Steps) -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۲</div>
|
||||
<div class="section-title">
|
||||
<h3>سایر مراحل (بدون تغییر)</h3>
|
||||
<div class="subtitle">Other Steps (Unchanged)</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>بقیه مراحل (نصب بسته، تعریف Tool، حذف Startup.cs، ثبت رکورد در xAiApi و تست) همانند نسخه ۱.۱ باقی میمانند. برای کامل بودن، خلاصه آنها در ادامه آمده است:</p>
|
||||
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">گام ۲.۱ — نصب بستههای NuGet</h4>
|
||||
<pre data-lang="xml"><code><ItemGroup>
|
||||
<PackageReference Include="Grapevine.Extensions.Mcp" Version="5.0.2" />
|
||||
<PackageReference Include="ModelContextProtocol" Version="*" />
|
||||
</ItemGroup></code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲.۲ — تعریف Tool</h4>
|
||||
<div class="file-path">Tools/EchoTool.cs</div>
|
||||
<pre data-lang="csharp"><code>using System.ComponentModel;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer.Tools
|
||||
{
|
||||
[McpServerToolType]
|
||||
public static class EchoTool
|
||||
{
|
||||
[McpServerTool, Description("Echoes the message back to the client.")]
|
||||
public static string Echo(string message) => $"hello {message}";
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲.۳ — حذف یا غیرفعالسازی <code>Startup.cs</code></h4>
|
||||
<p>از آنجا که Grapevine مستقل از ASP.NET Core است، دیگر نیازی به <code>Startup.cs</code> و <code>ConfigureServices</code> نیست. میتوانید فایل <code>Startup.cs</code> را حذف کنید.</p>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۳ — اتصال <code>xAiApi</code></h4>
|
||||
<pre data-lang="json"><code>POST /McpServer
|
||||
{
|
||||
"name": "xAiMcpServer-Tools",
|
||||
"endpoint": "http://localhost:5000/mcp",
|
||||
"enabled": true,
|
||||
"scope": "Owner",
|
||||
"timeoutSeconds": 30,
|
||||
"description": "ابزارهای سازمانی از xAiMcpServer (Grapevine)"
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 3: Summary & Checklist -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۳</div>
|
||||
<div class="section-title">
|
||||
<h3>جمعبندی و چکلیست نهایی</h3>
|
||||
<div class="subtitle">Summary & Checklist</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>با اصلاح پیکربندی <code>RestServerBuilder</code>، خطای <code>IServiceCollection.Prefixes</code> برطرف شد و <code>xAiMcpServer</code> با حفظ <code>netcoreapp3.1</code>، به یک MCP Server فعال با HTTP Transport تبدیل میشود.</p>
|
||||
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">چکلیست نهایی:</h4>
|
||||
<ul class="checklist">
|
||||
<li>نصب بسته <code>Grapevine.Extensions.Mcp</code> (نسخه 5.0.2)</li>
|
||||
<li>تعریف <code>Tools/EchoTool.cs</code> با <code>[McpServerToolType]</code> و <code>[McpServerTool]</code></li>
|
||||
<li>بازنویسی <code>Program.cs</code> با دو لامبدای جداگانه (services و server)</li>
|
||||
<li>حذف یا غیرفعالسازی <code>Startup.cs</code></li>
|
||||
<li>ثبت رکورد <code>XAiMcpServer</code> در <code>xAiApi</code> با Endpoint <code>http://localhost:5000/mcp</code></li>
|
||||
<li>تست اتصال از طریق <code>GetAvailableToolsAsync</code></li>
|
||||
</ul>
|
||||
|
||||
<div class="conclusion-box">
|
||||
<h3>🎯 نتیجه نهایی</h3>
|
||||
<p>خطای <code>IServiceCollection.Prefixes</code> با جداسازی صحیح لامبداهای <code>RestServerBuilder</code> برطرف شد.</p>
|
||||
<p>اکنون <code>xAiMcpServer</code> با <code>netcoreapp3.1</code> و HTTP Transport فعال است و <code>xAiApi</code> میتواند ابزارهای آن را کشف و استفاده کند.</p>
|
||||
<div class="highlight" style="background: rgba(201,169,97,0.2); padding: 15px; border-radius: 8px; margin-top: 20px; border: 1px solid rgba(201,169,97,0.4);">
|
||||
<strong>💎 ارزش پیشنهادی:</strong><br>
|
||||
حفظ <code>netcoreapp3.1</code> + پیکربندی صحیح Grapevine + MCP Server فعال + اتصال کامل به <code>xAiApi</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>📞 گام بعدی:</strong> یک Tool واقعی (مانند <code>SearchKnowledge</code> یا <code>GetProjectInfo</code>) را پیادهسازی کنید و از طریق <code>xAiApi</code> فراخوانی نمایید.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-info" style="text-align: center; padding: 15px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 30px;">
|
||||
این مستند محرمانه بوده و صرفاً جهت استفاده تیم توسعه xSaherelmWorkspace تهیه شده است.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="document-footer">
|
||||
<div class="footer-brand">طراحی و مستندسازی: تیم معماری xSaherelmWorkspace</div>
|
||||
<div class="footer-divider"></div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۲ (اصلاحشده) | طبقهبندی: فنی-داخلی</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,531 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>پیادهسازی MCP Server با Grapevine روی netcoreapp3.1 — نسخه ۱.۶</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||
|
||||
:root {
|
||||
--primary: #1a365d;
|
||||
--primary-light: #2c5282;
|
||||
--accent: #c9a961;
|
||||
--accent-dark: #a8893f;
|
||||
--bg: #faf9f6;
|
||||
--card-bg: #ffffff;
|
||||
--text: #1a202c;
|
||||
--text-muted: #4a5568;
|
||||
--border: #e2e8f0;
|
||||
--success: #38a169;
|
||||
--danger: #e53e3e;
|
||||
--warning: #dd6b20;
|
||||
--code-bg: #1e293b;
|
||||
--code-text: #e2e8f0;
|
||||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.9;
|
||||
font-size: 15px;
|
||||
padding: 30px 15px;
|
||||
}
|
||||
|
||||
.document-container {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
background: var(--card-bg);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.document-header {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||||
color: white;
|
||||
padding: 50px 40px 40px;
|
||||
position: relative;
|
||||
border-bottom: 4px solid var(--accent);
|
||||
}
|
||||
|
||||
.document-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; right: 0;
|
||||
width: 200px; height: 200px;
|
||||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||||
|
||||
.company-logo {
|
||||
width: 60px; height: 60px;
|
||||
background: var(--accent);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||||
.doc-meta div { margin-bottom: 3px; }
|
||||
|
||||
.document-title {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.document-title .label {
|
||||
display: inline-block;
|
||||
background: rgba(201,169,97,0.2);
|
||||
color: var(--accent);
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid rgba(201,169,97,0.4);
|
||||
}
|
||||
|
||||
.document-title h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.document-title h2 { font-size: 15px; font-weight: 400; opacity: 0.9; }
|
||||
|
||||
.document-body { padding: 40px; }
|
||||
|
||||
.intro-text {
|
||||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 20px 25px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 35px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section { margin-bottom: 45px; page-break-inside: avoid; }
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-number {
|
||||
width: 50px; height: 50px;
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||||
}
|
||||
|
||||
.section-title { flex: 1; }
|
||||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; direction: ltr; text-align: right; }
|
||||
|
||||
.section-content { padding-right: 10px; }
|
||||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||||
.section-content p.no-indent { text-indent: 0; }
|
||||
|
||||
.highlight-box, .info-box, .success-box, .warning-box, .danger-box {
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.highlight-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #f6e05e;
|
||||
border-right: 4px solid var(--accent);
|
||||
}
|
||||
.highlight-box strong { color: var(--accent-dark); }
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||||
border: 1px solid #90cdf4;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.success-box {
|
||||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||||
border: 1px solid #9ae6b4;
|
||||
border-right: 4px solid var(--success);
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #fbd38d;
|
||||
border-right: 4px solid var(--warning);
|
||||
}
|
||||
|
||||
.danger-box {
|
||||
background: linear-gradient(to left, #fff5f5, #fed7d7);
|
||||
border: 1px solid #fc8181;
|
||||
border-right: 4px solid var(--danger);
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--code-bg);
|
||||
color: var(--code-text);
|
||||
padding: 20px 22px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
border: 1px solid #334155;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
pre::before {
|
||||
content: attr(data-lang);
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 12px;
|
||||
font-size: 10px;
|
||||
color: #64748b;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
background: #f1f5f9;
|
||||
color: #1e293b;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
pre code { background: none; color: inherit; padding: 0; display: inline; }
|
||||
|
||||
.file-path {
|
||||
background: #2c5282;
|
||||
color: #bee3f8;
|
||||
padding: 8px 14px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
margin-bottom: -15px;
|
||||
border-bottom: 2px solid #1a365d;
|
||||
}
|
||||
|
||||
.file-path::before { content: '📄 '; margin-left: 4px; }
|
||||
|
||||
.styled-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.styled-table thead {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
}
|
||||
|
||||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||||
|
||||
.checklist { list-style: none; padding: 0; margin: 15px 0; }
|
||||
.checklist li {
|
||||
padding: 10px 15px;
|
||||
background: #f8fafc;
|
||||
border-right: 3px solid var(--primary-light);
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.checklist li::before {
|
||||
content: '✓';
|
||||
color: var(--success);
|
||||
font-weight: 700;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.conclusion-box {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
margin: 30px 0;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||||
}
|
||||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||||
|
||||
.document-footer {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 25px 40px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||||
|
||||
@media print { body { background: white; padding: 0; } .document-container { box-shadow: none; border-radius: 0; } .section { page-break-inside: avoid; } }
|
||||
@media (max-width: 768px) { .document-body { padding: 25px 20px; } .document-header { padding: 30px 20px; } .header-top { flex-direction: column; gap: 15px; } .doc-meta { text-align: center; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="document-container">
|
||||
|
||||
<header class="document-header">
|
||||
<div class="header-top">
|
||||
<div class="company-badge"><div class="company-logo"></div></div>
|
||||
<div class="doc-meta">
|
||||
<div>شماره مستند: ARCH-MCP-HTTP-1405-001-R6</div>
|
||||
<div>نسخه: ۱.۶ (نهایی)</div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||||
<div>طبقهبندی: فنی-داخلی</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="document-title">
|
||||
<span class="label">TECHNICAL DESIGN DOCUMENT — R6</span>
|
||||
<h1>پیادهسازی MCP Server با Grapevine روی netcoreapp3.1</h1>
|
||||
<h2>رفع خطای TypeLoadException با پین کردن نسخه ModelContextProtocol 2.2.0</h2>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="document-body">
|
||||
|
||||
<div class="intro-text">
|
||||
<strong>هدف مستند (نسخه ۱.۶):</strong><br>
|
||||
این نسخه پس از بروز خطای <code>TypeLoadException</code> برای <code>McpServerOptions</code> بازنویسی شده است. علت خطا، انتقال کلاس <code>McpServerOptions</code> به اسمبلی <code>ModelContextProtocol.Core</code> در نسخههای جدید (2.3.1.0) بود، در حالی که <code>Grapevine.Extensions.Mcp 5.0.2</code> انتظار دارد آن را در اسمبلی اصلی <code>ModelContextProtocol</code> بیابد. راهحل نهایی، پین کردن <code>ModelContextProtocol</code> به نسخه <strong>2.2.0</strong> و استفاده از ساختار صحیح <code>Program.cs</code> با دو لامبدای جداگانه است.
|
||||
</div>
|
||||
|
||||
<!-- SECTION 0: Root Cause -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۰</div>
|
||||
<div class="section-title">
|
||||
<h3>ریشهیابی خطای <code>TypeLoadException</code></h3>
|
||||
<div class="subtitle">Root Cause: Assembly Mismatch</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>خطای <code>'Could not load type 'ModelContextProtocol.Server.McpServerOptions' from assembly 'ModelContextProtocol, Version=2.3.1.0'</code> نشان میدهد که Grapevine به دنبال <code>McpServerOptions</code> در اسمبلی <code>ModelContextProtocol</code> میگردد، اما در نسخه 2.3.1.0 این کلاس به <code>ModelContextProtocol.Core.dll</code> منتقل شده است[reference:2].</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>بسته</th>
|
||||
<th>نسخه</th>
|
||||
<th>محل <code>McpServerOptions</code></th>
|
||||
<th>سازگاری با Grapevine 5.0.2</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>ModelContextProtocol</code></td>
|
||||
<td>2.3.1.0</td>
|
||||
<td>در <code>ModelContextProtocol.Core</code></td>
|
||||
<td style="color: var(--danger); font-weight: 600;">✗ خیر (TypeLoadException)</td>
|
||||
</tr>
|
||||
<tr class="highlight-row">
|
||||
<td><code>ModelContextProtocol</code></td>
|
||||
<td><strong>2.2.0</strong></td>
|
||||
<td>در اسمبلی اصلی <code>ModelContextProtocol</code></td>
|
||||
<td style="color: var(--success); font-weight: 700;">✓ بله</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="danger-box">
|
||||
<strong>⚠️ نتیجه:</strong> با پین کردن نسخه <code>ModelContextProtocol</code> به <strong>2.2.0</strong>، کلاس <code>McpServerOptions</code> در محل مورد انتظار Grapevine قرار میگیرد و خطا برطرف میشود.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 1: Solution -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱</div>
|
||||
<div class="section-title">
|
||||
<h3>راهحل: پیادهسازی صحیح با Grapevine</h3>
|
||||
<div class="subtitle">Correct Implementation with Grapevine</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">گام ۱ — تنظیم بستهها</h4>
|
||||
<div class="file-path">xAiMcpServer.csproj</div>
|
||||
<pre data-lang="xml"><code><ItemGroup>
|
||||
<PackageReference Include="Grapevine.Extensions.Mcp" Version="5.0.2" />
|
||||
<PackageReference Include="ModelContextProtocol" Version="2.2.0" />
|
||||
</ItemGroup></code></pre>
|
||||
<p>از نصب <code>ModelContextProtocol.AspNetCore</code> خودداری کنید.</p>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲ — تعریف Tool</h4>
|
||||
<div class="file-path">Tools/EchoTool.cs</div>
|
||||
<pre data-lang="csharp"><code>using System.ComponentModel;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer.Tools
|
||||
{
|
||||
[McpServerToolType]
|
||||
public static class EchoTool
|
||||
{
|
||||
[McpServerTool, Description("Echoes the message back to the client.")]
|
||||
public static string Echo(string message) => $"hello {message}";
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۳ — پیادهسازی <code>Program.cs</code></h4>
|
||||
<div class="file-path">Program.cs</div>
|
||||
<pre data-lang="csharp"><code>using System;
|
||||
using Grapevine;
|
||||
using Grapevine.Extensions.Mcp;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = new RestServerBuilder(
|
||||
// لامبدای اول: ثبت سرویسهای MCP (نوع: IServiceCollection)
|
||||
services => services
|
||||
.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithToolsFromAssembly(),
|
||||
|
||||
// لامبدای دوم: تنظیم سرور Grapevine (نوع صریح: IRestServer)
|
||||
(IRestServer server) =>
|
||||
{
|
||||
server.Prefixes.Add("http://localhost:5000/");
|
||||
}
|
||||
);
|
||||
|
||||
var server = builder.Build();
|
||||
server.MapMcp("/mcp"); // فعالسازی مسیر JSON-RPC
|
||||
server.Start();
|
||||
|
||||
Console.WriteLine("MCP Server running on http://localhost:5000/mcp");
|
||||
Console.WriteLine("Press Enter to stop...");
|
||||
Console.ReadLine();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✓ نکات کلیدی:</strong>
|
||||
<ul style="padding-right: 20px; margin-top: 10px;">
|
||||
<li>دو لامبدا باید با کاما از هم جدا شوند.</li>
|
||||
<li>نوع پارامتر دوم باید صریحاً <code>(IRestServer server)</code> نوشته شود تا خطای <code>Prefixes</code> رخ ندهد.</li>
|
||||
<li>فراخوانی <code>server.MapMcp("/mcp")</code> برای ثبت مسیر MCP الزامی است.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۴ — اتصال از <code>xAiApi</code></h4>
|
||||
<pre data-lang="json"><code>POST /McpServer
|
||||
{
|
||||
"name": "xAiMcpServer-Tools",
|
||||
"endpoint": "http://localhost:5000/mcp",
|
||||
"enabled": true,
|
||||
"scope": "Owner",
|
||||
"timeoutSeconds": 30,
|
||||
"description": "ابزارهای سازمانی از xAiMcpServer (Grapevine)"
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 2: Summary -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۲</div>
|
||||
<div class="section-title">
|
||||
<h3>جمعبندی و چکلیست</h3>
|
||||
<div class="subtitle">Summary & Checklist</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<ul class="checklist">
|
||||
<li>پین کردن <code>ModelContextProtocol</code> به نسخه <strong>2.2.0</strong></li>
|
||||
<li>نصب <code>Grapevine.Extensions.Mcp</code> نسخه 5.0.2</li>
|
||||
<li>تعریف <code>Tools/EchoTool.cs</code> با <code>[McpServerToolType]</code></li>
|
||||
<li>پیادهسازی <code>Program.cs</code> با دو لامبدای جداگانه و نوع صریح <code>IRestServer</code></li>
|
||||
<li>افزودن <code>server.MapMcp("/mcp")</code></li>
|
||||
<li>ثبت رکورد در <code>xAiApi</code> با Endpoint <code>http://localhost:5000/mcp</code></li>
|
||||
</ul>
|
||||
|
||||
<div class="conclusion-box">
|
||||
<h3>🎯 نتیجه نهایی</h3>
|
||||
<p>خطای <code>TypeLoadException</code> با پین کردن نسخه <code>ModelContextProtocol</code> به 2.2.0 برطرف شد و MCP Server با Grapevine روی <code>netcoreapp3.1</code> فعال میشود.</p>
|
||||
<div class="highlight" style="background: rgba(201,169,97,0.2); padding: 15px; border-radius: 8px; margin-top: 20px; border: 1px solid rgba(201,169,97,0.4);">
|
||||
<strong>💎 ارزش پیشنهادی:</strong><br>
|
||||
حفظ <code>netcoreapp3.1</code> + رفع خطای نسخهای + MCP Server فعال + اتصال کامل به <code>xAiApi</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-info" style="text-align: center; padding: 15px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 30px;">
|
||||
این مستند محرمانه بوده و صرفاً جهت استفاده تیم توسعه xSaherelmWorkspace تهیه شده است.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="document-footer">
|
||||
<div class="footer-brand">طراحی و مستندسازی: تیم معماری xSaherelmWorkspace</div>
|
||||
<div class="footer-divider"></div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۶ | طبقهبندی: فنی-داخلی</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,576 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>پیادهسازی MCP Server روی netcoreapp3.1 — رفع خطای TypeLoadException</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||
|
||||
:root {
|
||||
--primary: #1a365d;
|
||||
--primary-light: #2c5282;
|
||||
--accent: #c9a961;
|
||||
--accent-dark: #a8893f;
|
||||
--bg: #faf9f6;
|
||||
--card-bg: #ffffff;
|
||||
--text: #1a202c;
|
||||
--text-muted: #4a5568;
|
||||
--border: #e2e8f0;
|
||||
--success: #38a169;
|
||||
--danger: #e53e3e;
|
||||
--warning: #dd6b20;
|
||||
--code-bg: #1e293b;
|
||||
--code-text: #e2e8f0;
|
||||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.9;
|
||||
font-size: 15px;
|
||||
padding: 30px 15px;
|
||||
}
|
||||
|
||||
.document-container {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
background: var(--card-bg);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.document-header {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||||
color: white;
|
||||
padding: 50px 40px 40px;
|
||||
position: relative;
|
||||
border-bottom: 4px solid var(--accent);
|
||||
}
|
||||
|
||||
.document-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; right: 0;
|
||||
width: 200px; height: 200px;
|
||||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||||
|
||||
.company-logo {
|
||||
width: 60px; height: 60px;
|
||||
background: var(--accent);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||||
.doc-meta div { margin-bottom: 3px; }
|
||||
|
||||
.document-title {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.document-title .label {
|
||||
display: inline-block;
|
||||
background: rgba(201,169,97,0.2);
|
||||
color: var(--accent);
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid rgba(201,169,97,0.4);
|
||||
}
|
||||
|
||||
.document-title h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.document-title h2 { font-size: 15px; font-weight: 400; opacity: 0.9; }
|
||||
|
||||
.document-body { padding: 40px; }
|
||||
|
||||
.intro-text {
|
||||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 20px 25px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 35px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section { margin-bottom: 45px; page-break-inside: avoid; }
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-number {
|
||||
width: 50px; height: 50px;
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||||
}
|
||||
|
||||
.section-title { flex: 1; }
|
||||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; direction: ltr; text-align: right; }
|
||||
|
||||
.section-content { padding-right: 10px; }
|
||||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||||
.section-content p.no-indent { text-indent: 0; }
|
||||
|
||||
.highlight-box, .info-box, .success-box, .warning-box, .danger-box {
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.highlight-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #f6e05e;
|
||||
border-right: 4px solid var(--accent);
|
||||
}
|
||||
.highlight-box strong { color: var(--accent-dark); }
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||||
border: 1px solid #90cdf4;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.success-box {
|
||||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||||
border: 1px solid #9ae6b4;
|
||||
border-right: 4px solid var(--success);
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #fbd38d;
|
||||
border-right: 4px solid var(--warning);
|
||||
}
|
||||
|
||||
.danger-box {
|
||||
background: linear-gradient(to left, #fff5f5, #fed7d7);
|
||||
border: 1px solid #fc8181;
|
||||
border-right: 4px solid var(--danger);
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--code-bg);
|
||||
color: var(--code-text);
|
||||
padding: 20px 22px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
border: 1px solid #334155;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
pre::before {
|
||||
content: attr(data-lang);
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 12px;
|
||||
font-size: 10px;
|
||||
color: #64748b;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
background: #f1f5f9;
|
||||
color: #1e293b;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
pre code { background: none; color: inherit; padding: 0; display: inline; }
|
||||
|
||||
.file-path {
|
||||
background: #2c5282;
|
||||
color: #bee3f8;
|
||||
padding: 8px 14px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
margin-bottom: -15px;
|
||||
border-bottom: 2px solid #1a365d;
|
||||
}
|
||||
|
||||
.file-path::before { content: '📄 '; margin-left: 4px; }
|
||||
|
||||
.styled-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.styled-table thead {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
}
|
||||
|
||||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||||
|
||||
.checklist { list-style: none; padding: 0; margin: 15px 0; }
|
||||
.checklist li {
|
||||
padding: 10px 15px;
|
||||
background: #f8fafc;
|
||||
border-right: 3px solid var(--primary-light);
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.checklist li::before {
|
||||
content: '✓';
|
||||
color: var(--success);
|
||||
font-weight: 700;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.conclusion-box {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
margin: 30px 0;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||||
}
|
||||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||||
|
||||
.document-footer {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 25px 40px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||||
|
||||
@media print { body { background: white; padding: 0; } .document-container { box-shadow: none; border-radius: 0; } .section { page-break-inside: avoid; } }
|
||||
@media (max-width: 768px) { .document-body { padding: 25px 20px; } .document-header { padding: 30px 20px; } .header-top { flex-direction: column; gap: 15px; } .doc-meta { text-align: center; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="document-container">
|
||||
|
||||
<header class="document-header">
|
||||
<div class="header-top">
|
||||
<div class="company-badge"><div class="company-logo"></div></div>
|
||||
<div class="doc-meta">
|
||||
<div>شماره مستند: ARCH-MCP-HTTP-1405-001-R5</div>
|
||||
<div>نسخه: ۱.۵ (رفع TypeLoadException)</div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||||
<div>طبقهبندی: فنی-داخلی</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="document-title">
|
||||
<span class="label">TECHNICAL DESIGN DOCUMENT — R5</span>
|
||||
<h1>پیادهسازی MCP Server روی netcoreapp3.1</h1>
|
||||
<h2>رفع خطای TypeLoadException با پیادهسازی دستی JSON-RPC و ModelContextProtocol 2.2.0</h2>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="document-body">
|
||||
|
||||
<div class="intro-text">
|
||||
<strong>هدف مستند (نسخه ۱.۵):</strong><br>
|
||||
این نسخه پس از بروز خطای <code>TypeLoadException</code> برای <code>McpServerOptions</code> در <code>Grapevine.Extensions.Mcp</code> بازنویسی شده است. علت خطا، ناسازگاری نسخهای بین <code>Grapevine.Extensions.Mcp 5.0.2</code> (مبتنی بر .NET 6.0) و <code>ModelContextProtocol 2.3.1.0</code> است. راهحل نهایی، حذف Grapevine و پیادهسازی یک Endpoint سفارشی JSON-RPC روی ASP.NET Core 3.1 با استفاده از <code>ModelContextProtocol 2.2.0</code> (که رسماً از <code>netcoreapp3.1</code> پشتیبانی میکند) است.
|
||||
</div>
|
||||
|
||||
<!-- SECTION 0: Root Cause -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۰</div>
|
||||
<div class="section-title">
|
||||
<h3>ریشهیابی خطای <code>TypeLoadException</code></h3>
|
||||
<div class="subtitle">Root Cause: Version Mismatch</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>خطای <code>'Could not load type 'ModelContextProtocol.Server.McpServerOptions' from assembly 'ModelContextProtocol, Version=2.3.1.0'</code> نشان میدهد که اسمبلی <code>Grapevine.Extensions.Mcp</code> انتظار دارد نوع <code>McpServerOptions</code> در اسمبلی <code>ModelContextProtocol</code> وجود داشته باشد، اما در نسخه 2.3.1.0 این نوع یا حذف شده یا به اسمبلی دیگری منتقل شده است.</p>
|
||||
|
||||
<table class="styled-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>بسته</th>
|
||||
<th>نسخه</th>
|
||||
<th>Target Framework</th>
|
||||
<th>سازگاری با netcoreapp3.1</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code>Grapevine.Extensions.Mcp</code></td>
|
||||
<td>5.0.2</td>
|
||||
<td>.NET 6.0</td>
|
||||
<td style="color: var(--danger); font-weight: 600;">✗ خیر</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>ModelContextProtocol</code></td>
|
||||
<td>2.3.1.0</td>
|
||||
<td>netstandard2.0 / .NET 8+</td>
|
||||
<td style="color: var(--warning);">⚠ ناسازگاری نوع</td>
|
||||
</tr>
|
||||
<tr class="highlight-row">
|
||||
<td><code>ModelContextProtocol</code></td>
|
||||
<td><strong>2.2.0</strong></td>
|
||||
<td>netstandard2.0</td>
|
||||
<td style="color: var(--success); font-weight: 700;">✓ بله</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="danger-box">
|
||||
<strong>⚠️ نتیجه:</strong> <code>Grapevine.Extensions.Mcp 5.0.2</code> روی <code>netcoreapp3.1</code> قابل اجرا نیست. باید آن را حذف کرده و یک Endpoint سفارشی JSON-RPC با <code>ModelContextProtocol 2.2.0</code> پیادهسازی کنید.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 1: Solution -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱</div>
|
||||
<div class="section-title">
|
||||
<h3>راهحل: Endpoint سفارشی JSON-RPC روی ASP.NET Core 3.1</h3>
|
||||
<div class="subtitle">Custom JSON-RPC Endpoint with ModelContextProtocol 2.2.0</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">گام ۱ — تنظیم بستهها</h4>
|
||||
<div class="file-path">xAiMcpServer.csproj</div>
|
||||
<pre data-lang="xml"><code><ItemGroup>
|
||||
<PackageReference Include="ModelContextProtocol" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.32" />
|
||||
</ItemGroup></code></pre>
|
||||
<p>بسته <code>Grapevine.Extensions.Mcp</code> را حذف کنید.</p>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۲ — تعریف Tool</h4>
|
||||
<div class="file-path">Tools/EchoTool.cs</div>
|
||||
<pre data-lang="csharp"><code>using System.ComponentModel;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer.Tools
|
||||
{
|
||||
[McpServerToolType]
|
||||
public static class EchoTool
|
||||
{
|
||||
[McpServerTool, Description("Echoes the message back to the client.")]
|
||||
public static string Echo(string message) => $"hello {message}";
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۳ — پیادهسازی Endpoint در Startup.cs</h4>
|
||||
<pre data-lang="csharp"><code>using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration) => Configuration = configuration;
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMcpServer()
|
||||
.WithToolsFromAssembly();
|
||||
services.AddControllers();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapPost("/mcp", async context =>
|
||||
{
|
||||
using var reader = new System.IO.StreamReader(context.Request.Body);
|
||||
var body = await reader.ReadToEndAsync();
|
||||
if (string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
return;
|
||||
}
|
||||
|
||||
// پردازش JSON-RPC (نمونه ساده برای tools/list)
|
||||
var request = JsonSerializer.Deserialize<JsonRpcRequest>(body);
|
||||
if (request?.Method == "tools/list")
|
||||
{
|
||||
var response = new
|
||||
{
|
||||
jsonrpc = "2.0",
|
||||
id = request.Id,
|
||||
result = new
|
||||
{
|
||||
tools = new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
name = "Echo",
|
||||
description = "Echoes the message back",
|
||||
inputSchema = new
|
||||
{
|
||||
type = "object",
|
||||
properties = new
|
||||
{
|
||||
message = new { type = "string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
context.Response.ContentType = "application/json";
|
||||
await context.Response.WriteAsync(JsonSerializer.Serialize(response));
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
}
|
||||
});
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class JsonRpcRequest
|
||||
{
|
||||
public string Jsonrpc { get; set; }
|
||||
public string Method { get; set; }
|
||||
public object Id { get; set; }
|
||||
public JsonElement Params { get; set; }
|
||||
}</code></pre>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>💡 نکته:</strong> این پیادهسازی ساده، فقط متد <code>tools/list</code> را پشتیبانی میکند. برای پیادهسازی کامل (شامل <code>initialize</code>، <code>tools/call</code>، <code>notifications</code>)، باید منطق را گسترش دهید. میتوانید از نمونههای موجود در مخزن GitHub SDK الهام بگیرید.
|
||||
</div>
|
||||
|
||||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">گام ۴ — ثبت رکورد در xAiApi</h4>
|
||||
<pre data-lang="json"><code>POST /McpServer
|
||||
{
|
||||
"name": "xAiMcpServer-Tools",
|
||||
"endpoint": "http://localhost:5000/mcp",
|
||||
"enabled": true,
|
||||
"scope": "Owner",
|
||||
"timeoutSeconds": 30
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 2: Summary -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۲</div>
|
||||
<div class="section-title">
|
||||
<h3>جمعبندی و چکلیست</h3>
|
||||
<div class="subtitle">Summary & Checklist</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<ul class="checklist">
|
||||
<li>حذف بسته <code>Grapevine.Extensions.Mcp</code> از پروژه</li>
|
||||
<li>تنظیم <code>ModelContextProtocol</code> روی نسخه <strong>2.2.0</strong></li>
|
||||
<li>تعریف <code>Tools/EchoTool.cs</code> با <code>[McpServerToolType]</code></li>
|
||||
<li>پیادهسازی Endpoint سفارشی JSON-RPC در <code>Startup.cs</code></li>
|
||||
<li>ثبت رکورد در <code>xAiApi</code> با Endpoint <code>http://localhost:5000/mcp</code></li>
|
||||
</ul>
|
||||
|
||||
<div class="conclusion-box">
|
||||
<h3>🎯 نتیجه نهایی</h3>
|
||||
<p>خطای <code>TypeLoadException</code> با حذف Grapevine و استفاده از <code>ModelContextProtocol 2.2.0</code> بههمراه Endpoint سفارشی JSON-RPC برطرف میشود.</p>
|
||||
<p>این راهحل، حفظ <code>netcoreapp3.1</code> را تضمین کرده و اتصال <code>xAiApi</code> به MCP Server را ممکن میسازد.</p>
|
||||
<div class="highlight" style="background: rgba(201,169,97,0.2); padding: 15px; border-radius: 8px; margin-top: 20px; border: 1px solid rgba(201,169,97,0.4);">
|
||||
<strong>💎 ارزش پیشنهادی:</strong><br>
|
||||
حفظ <code>netcoreapp3.1</code> + رفع کامل خطای نسخهای + MCP Server فعال + اتصال به <code>xAiApi</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-info" style="text-align: center; padding: 15px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 30px;">
|
||||
این مستند محرمانه بوده و صرفاً جهت استفاده تیم توسعه xSaherelmWorkspace تهیه شده است.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="document-footer">
|
||||
<div class="footer-brand">طراحی و مستندسازی: تیم معماری xSaherelmWorkspace</div>
|
||||
<div class="footer-divider"></div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۵ | طبقهبندی: فنی-داخلی</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,600 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1) — نسخه ۱.۴</title>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||
|
||||
:root {
|
||||
--primary: #1a365d;
|
||||
--primary-light: #2c5282;
|
||||
--accent: #c9a961;
|
||||
--accent-dark: #a8893f;
|
||||
--bg: #faf9f6;
|
||||
--card-bg: #ffffff;
|
||||
--text: #1a202c;
|
||||
--text-muted: #4a5568;
|
||||
--border: #e2e8f0;
|
||||
--success: #38a169;
|
||||
--danger: #e53e3e;
|
||||
--warning: #dd6b20;
|
||||
--code-bg: #1e293b;
|
||||
--code-text: #e2e8f0;
|
||||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.9;
|
||||
font-size: 15px;
|
||||
padding: 30px 15px;
|
||||
}
|
||||
|
||||
.document-container {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
background: var(--card-bg);
|
||||
box-shadow: var(--shadow);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.document-header {
|
||||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||||
color: white;
|
||||
padding: 50px 40px 40px;
|
||||
position: relative;
|
||||
border-bottom: 4px solid var(--accent);
|
||||
}
|
||||
|
||||
.document-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0; right: 0;
|
||||
width: 200px; height: 200px;
|
||||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
transform: translate(50%, -50%);
|
||||
}
|
||||
|
||||
.header-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||||
|
||||
.company-logo {
|
||||
width: 60px; height: 60px;
|
||||
background: var(--accent);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||||
.doc-meta div { margin-bottom: 3px; }
|
||||
|
||||
.document-title {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.document-title .label {
|
||||
display: inline-block;
|
||||
background: rgba(201,169,97,0.2);
|
||||
color: var(--accent);
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid rgba(201,169,97,0.4);
|
||||
}
|
||||
|
||||
.document-title h1 {
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
margin-bottom: 10px;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
|
||||
.document-title h2 { font-size: 15px; font-weight: 400; opacity: 0.9; }
|
||||
|
||||
.document-body { padding: 40px; }
|
||||
|
||||
.intro-text {
|
||||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||||
border-right: 4px solid var(--accent);
|
||||
padding: 20px 25px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 35px;
|
||||
font-size: 14px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.section { margin-bottom: 45px; page-break-inside: avoid; }
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 2px solid var(--border);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-number {
|
||||
width: 50px; height: 50px;
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 800;
|
||||
font-size: 20px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||||
}
|
||||
|
||||
.section-title { flex: 1; }
|
||||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; direction: ltr; text-align: right; }
|
||||
|
||||
.section-content { padding-right: 10px; }
|
||||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||||
.section-content p.no-indent { text-indent: 0; }
|
||||
|
||||
.highlight-box, .info-box, .success-box, .warning-box, .danger-box {
|
||||
padding: 18px 22px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.highlight-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #f6e05e;
|
||||
border-right: 4px solid var(--accent);
|
||||
}
|
||||
.highlight-box strong { color: var(--accent-dark); }
|
||||
|
||||
.info-box {
|
||||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||||
border: 1px solid #90cdf4;
|
||||
border-right: 4px solid var(--primary-light);
|
||||
}
|
||||
|
||||
.success-box {
|
||||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||||
border: 1px solid #9ae6b4;
|
||||
border-right: 4px solid var(--success);
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||||
border: 1px solid #fbd38d;
|
||||
border-right: 4px solid var(--warning);
|
||||
}
|
||||
|
||||
.danger-box {
|
||||
background: linear-gradient(to left, #fff5f5, #fed7d7);
|
||||
border: 1px solid #fc8181;
|
||||
border-right: 4px solid var(--danger);
|
||||
}
|
||||
|
||||
pre {
|
||||
background: var(--code-bg);
|
||||
color: var(--code-text);
|
||||
padding: 20px 22px;
|
||||
border-radius: 8px;
|
||||
overflow-x: auto;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
border: 1px solid #334155;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
pre::before {
|
||||
content: attr(data-lang);
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 12px;
|
||||
font-size: 10px;
|
||||
color: #64748b;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: 'JetBrains Mono', 'Courier New', monospace;
|
||||
background: #f1f5f9;
|
||||
color: #1e293b;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
pre code { background: none; color: inherit; padding: 0; display: inline; }
|
||||
|
||||
.file-path {
|
||||
background: #2c5282;
|
||||
color: #bee3f8;
|
||||
padding: 8px 14px;
|
||||
border-radius: 6px 6px 0 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
margin-top: 15px;
|
||||
margin-bottom: -15px;
|
||||
border-bottom: 2px solid #1a365d;
|
||||
}
|
||||
|
||||
.file-path::before { content: '📄 '; margin-left: 4px; }
|
||||
|
||||
.styled-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 20px 0;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
.styled-table thead {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
}
|
||||
|
||||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||||
|
||||
.file-tree {
|
||||
background: #f8fafc;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 20px 25px;
|
||||
margin: 15px 0;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 12.5px;
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
line-height: 1.9;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.file-tree .folder { color: var(--primary); font-weight: 600; }
|
||||
.file-tree .new { color: var(--success); }
|
||||
.file-tree .modify { color: var(--warning); }
|
||||
|
||||
.checklist { list-style: none; padding: 0; margin: 15px 0; }
|
||||
.checklist li {
|
||||
padding: 10px 15px;
|
||||
background: #f8fafc;
|
||||
border-right: 3px solid var(--primary-light);
|
||||
margin-bottom: 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.checklist li::before {
|
||||
content: '✓';
|
||||
color: var(--success);
|
||||
font-weight: 700;
|
||||
margin-left: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.conclusion-box {
|
||||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||||
color: white;
|
||||
padding: 30px;
|
||||
border-radius: 12px;
|
||||
margin: 30px 0;
|
||||
text-align: center;
|
||||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||||
}
|
||||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||||
|
||||
.document-footer {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 25px 40px;
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||||
|
||||
@media print { body { background: white; padding: 0; } .document-container { box-shadow: none; border-radius: 0; } .section { page-break-inside: avoid; } }
|
||||
@media (max-width: 768px) { .document-body { padding: 25px 20px; } .document-header { padding: 30px 20px; } .header-top { flex-direction: column; gap: 15px; } .doc-meta { text-align: center; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="document-container">
|
||||
|
||||
<header class="document-header">
|
||||
<div class="header-top">
|
||||
<div class="company-badge"><div class="company-logo"></div></div>
|
||||
<div class="doc-meta">
|
||||
<div>شماره مستند: ARCH-MCP-HTTP-1405-001-R4</div>
|
||||
<div>نسخه: ۱.۴ (دسترسی به IConfiguration)</div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||||
<div>طبقهبندی: فنی-داخلی</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="document-title">
|
||||
<span class="label">TECHNICAL DESIGN DOCUMENT — R4</span>
|
||||
<h1>پیادهسازی MCP Server با HTTP Transport در xAiMcpServer (netcoreapp3.1)</h1>
|
||||
<h2>دسترسی به IConfiguration و IServiceCollection در Program.cs</h2>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="document-body">
|
||||
|
||||
<div class="intro-text">
|
||||
<strong>هدف مستند (نسخه ۱.۴):</strong><br>
|
||||
این نسخه، روش دسترسی به <code>IConfiguration</code> و <code>IServiceCollection</code> را در <code>Program.cs</code> هنگام استفاده از <code>Grapevine.RestServerBuilder</code> شرح میدهد. از آنجا که این Builder خودش <code>IConfiguration</code> را فراهم نمیکند، باید آن را بهصورت دستی با <code>ConfigurationBuilder</code> بسازید و در لامبدای <code>services</code> برای ثبت سرویسها استفاده کنید. همچنین الگوی <code>Startup</code> (توصیهشده) برای کد تمیزتر معرفی میشود.
|
||||
</div>
|
||||
|
||||
<!-- SECTION 0: Why Manual Configuration -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۰</div>
|
||||
<div class="section-title">
|
||||
<h3>چرا باید <code>IConfiguration</code> را دستی بسازیم؟</h3>
|
||||
<div class="subtitle">Why Manual Configuration is Needed</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>برخلاف ASP.NET Core که <code>WebApplication.CreateBuilder(args)</code> بهصورت خودکار <code>IConfiguration</code> را از <code>appsettings.json</code> بارگذاری میکند، <code>Grapevine.RestServerBuilder</code> این کار را انجام نمیدهد. بنابراین، برای دسترسی به تنظیمات (مانند <code>XAppConfiguration</code> یا <code>ConnectionStrings</code>)، باید:</p>
|
||||
|
||||
<ul style="padding-right: 20px; margin: 10px 0;">
|
||||
<li><code>ConfigurationBuilder</code> را دستی بسازید.</li>
|
||||
<li>فایل <code>appsettings.json</code> را با <code>AddJsonFile</code> بارگذاری کنید.</li>
|
||||
<li>سپس در لامبدای <code>services</code>، از <code>configuration.GetSection().Get<T>()</code> برای ثبت سرویسها استفاده کنید.[reference:1]</li>
|
||||
</ul>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>💡 نکته:</strong> بستههای <code>Microsoft.Extensions.Configuration.Json</code> و <code>Microsoft.Extensions.Configuration.FileExtensions</code> را به پروژه اضافه کنید تا <code>ConfigurationBuilder</code> در دسترس باشد.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 1: Manual Configuration in Program.cs -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۱</div>
|
||||
<div class="section-title">
|
||||
<h3>روش اول: ساخت دستی <code>IConfiguration</code> در <code>Program.cs</code></h3>
|
||||
<div class="subtitle">Manual IConfiguration in Program.cs</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>کد زیر، <code>IConfiguration</code> را میسازد و در لامبدای <code>services</code> از آن استفاده میکند:</p>
|
||||
|
||||
<div class="file-path">Program.cs</div>
|
||||
<pre data-lang="csharp"><code>using System;
|
||||
using System.IO;
|
||||
using Grapevine;
|
||||
using Grapevine.Extensions.Mcp;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// ۱. ساخت IConfiguration از appsettings.json
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
|
||||
// ۲. ساخت RestServerBuilder با دسترسی به configuration
|
||||
var builder = new RestServerBuilder(
|
||||
// لامبدای اول: ثبت سرویسها
|
||||
services =>
|
||||
{
|
||||
// ثبت سرویسهای MCP
|
||||
services.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithToolsFromAssembly();
|
||||
|
||||
// ثبت IConfiguration بهعنوان Singleton (اختیاری)
|
||||
services.AddSingleton<IConfiguration>(configuration);
|
||||
|
||||
// ثبت سرویسهای سفارشی با استفاده از configuration
|
||||
// services.AddSingleton(
|
||||
// configuration.GetSection("XAppConfiguration").Get<XAppConfiguration>()
|
||||
// );
|
||||
// services.AddScoped<XValidationProvider>();
|
||||
},
|
||||
|
||||
// لامبدای دوم: تنظیمات IRestServer (نوع صریح)
|
||||
(IRestServer server) =>
|
||||
{
|
||||
server.Prefixes.Add("http://localhost:5000/");
|
||||
}
|
||||
);
|
||||
|
||||
var server = builder.Build();
|
||||
server.MapMcp("/mcp");
|
||||
server.Start();
|
||||
|
||||
Console.WriteLine("MCP Server running on http://localhost:5000/mcp");
|
||||
Console.ReadLine();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="success-box">
|
||||
<strong>✓ نکات کلیدی:</strong>
|
||||
<ul style="padding-right: 20px; margin-top: 10px;">
|
||||
<li>با ثبت <code>services.AddSingleton<IConfiguration>(configuration)</code>، سایر سرویسها میتوانند <code>IConfiguration</code> را از طریق تزریق وابستگی دریافت کنند.</li>
|
||||
<li>برای خواندن یک بخش خاص: <code>configuration.GetSection("XAppConfiguration").Get<XAppConfiguration>()</code>.</li>
|
||||
<li>مطمئن شوید <code>appsettings.json</code> در پوشه خروجی (Output Directory) کپی میشود (تنظیم <code>CopyToOutputDirectory</code> در <code>.csproj</code>).</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 2: Startup Class Approach -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۲</div>
|
||||
<div class="section-title">
|
||||
<h3>روش دوم (توصیهشده): الگوی <code>Startup</code> در Grapevine</h3>
|
||||
<div class="subtitle">Recommended: Grapevine Startup Class</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>نسخه ۵.۰ Grapevine از الگوی <code>Startup</code> پشتیبانی میکند که کد را تمیزتر و قابل نگهداریتر میکند. با استفاده از <code>RestServerBuilder.From<Startup>()</code>، میتوانید متدهای <code>ConfigureServices</code> و <code>ConfigureServer</code> را در یک کلاس جداگانه تعریف کنید.[reference:2]</p>
|
||||
|
||||
<div class="file-path">Startup.cs</div>
|
||||
<pre data-lang="csharp"><code>using System;
|
||||
using System.IO;
|
||||
using Grapevine;
|
||||
using Grapevine.Extensions.Mcp;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModelContextProtocol.Server;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public Startup()
|
||||
{
|
||||
_configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
}
|
||||
|
||||
// ثبت سرویسها
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMcpServer()
|
||||
.WithHttpTransport()
|
||||
.WithToolsFromAssembly();
|
||||
|
||||
services.AddSingleton<IConfiguration>(_configuration);
|
||||
// services.AddSingleton(_configuration.GetSection("XAppConfiguration").Get<XAppConfiguration>());
|
||||
}
|
||||
|
||||
// تنظیم سرور
|
||||
public void ConfigureServer(IRestServer server)
|
||||
{
|
||||
server.Prefixes.Add("http://localhost:5000/");
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="file-path">Program.cs</div>
|
||||
<pre data-lang="csharp"><code>using System;
|
||||
using Grapevine;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var server = RestServerBuilder.From<Startup>().Build();
|
||||
server.MapMcp("/mcp");
|
||||
server.Start();
|
||||
|
||||
Console.WriteLine("MCP Server running on http://localhost:5000/mcp");
|
||||
Console.ReadLine();
|
||||
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="info-box">
|
||||
<strong>💡 نکته:</strong> نام متدها مهم نیست؛ فقط امضاهای <code>public void ConfigureServices(IServiceCollection)</code> و <code>public void ConfigureServer(IRestServer)</code> مهم هستند. Grapevine با Reflection آنها را کشف میکند.[reference:3]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECTION 3: Summary -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-number">۳</div>
|
||||
<div class="section-title">
|
||||
<h3>جمعبندی و چکلیست</h3>
|
||||
<div class="subtitle">Summary & Checklist</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section-content">
|
||||
<p>برای دسترسی به <code>IConfiguration</code> و <code>IServiceCollection</code> در <code>Program.cs</code>:</p>
|
||||
|
||||
<ul class="checklist">
|
||||
<li>بستههای <code>Microsoft.Extensions.Configuration.Json</code> و <code>Microsoft.Extensions.Configuration.FileExtensions</code> را نصب کنید.</li>
|
||||
<li><code>ConfigurationBuilder</code> را در <code>Program.cs</code> (یا <code>Startup</code>) بسازید.</li>
|
||||
<li>در لامبدای <code>services</code>، سرویسها را با <code>configuration.GetSection().Get<T>()</code> ثبت کنید.</li>
|
||||
<li>برای کد تمیزتر، از الگوی <code>Startup</code> با <code>RestServerBuilder.From<Startup>()</code> استفاده کنید.</li>
|
||||
<li>مطمئن شوید <code>appsettings.json</code> در پوشه خروجی کپی میشود.</li>
|
||||
</ul>
|
||||
|
||||
<div class="conclusion-box">
|
||||
<h3>🎯 نتیجه نهایی</h3>
|
||||
<p>اکنون میتوانید <code>IConfiguration</code> را در <code>Program.cs</code> بسازید و سرویسهای سفارشی (مانند <code>XAppConfiguration</code>، <code>XValidationProvider</code> و...) را با استفاده از آن ثبت کنید.</p>
|
||||
<div class="highlight" style="background: rgba(201,169,97,0.2); padding: 15px; border-radius: 8px; margin-top: 20px; border: 1px solid rgba(201,169,97,0.4);">
|
||||
<strong>💎 ارزش پیشنهادی:</strong><br>
|
||||
دسترسی کامل به تنظیمات + ثبت سرویسهای سفارشی + حفظ <code>netcoreapp3.1</code> + کد تمیز با الگوی Startup
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-info" style="text-align: center; padding: 15px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 30px;">
|
||||
این مستند محرمانه بوده و صرفاً جهت استفاده تیم توسعه xSaherelmWorkspace تهیه شده است.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="document-footer">
|
||||
<div class="footer-brand">طراحی و مستندسازی: تیم معماری xSaherelmWorkspace</div>
|
||||
<div class="footer-divider"></div>
|
||||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۴ | طبقهبندی: فنی-داخلی</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+1923
-12
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,324 @@
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Program.cs
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Startup.cs
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using xAiMcpServer.DI;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using xIdentityService.DI;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Configurations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||
|
||||
namespace xAiMcpServer
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
//
|
||||
// Register Validation Provider and all XCommons Module Services ...
|
||||
services.AddXCommons(Configuration);
|
||||
|
||||
//
|
||||
// Register App Configuration ...
|
||||
services.AddXAppConfiguration(Configuration);
|
||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
||||
|
||||
//
|
||||
// Register Allowed Origins ...
|
||||
services.AddXCors(appConfiguration.AllowedOrigins);
|
||||
|
||||
//
|
||||
// Register Swagger ...
|
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
services.AddXSwagger(Configuration, xmlFilePath: xmlPath);
|
||||
|
||||
//
|
||||
// Add Api V1 Versioning ...
|
||||
services.AddXApiV1Versioning();
|
||||
|
||||
//
|
||||
// OAuthIntrospectin Http Client Handler ...
|
||||
// this is for handling SSLErrors ...
|
||||
services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName)
|
||||
.ConfigurePrimaryHttpMessageHandler(() =>
|
||||
{
|
||||
return new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Register Authorizations ...
|
||||
services.AddXAuthorization();
|
||||
|
||||
//
|
||||
services.AddControllers()
|
||||
.AddNewtonsoftJson(x =>
|
||||
{
|
||||
x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
x.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
||||
});
|
||||
|
||||
//
|
||||
var lifeTime = ServiceLifetime.Scoped;
|
||||
|
||||
//
|
||||
// Register XIdentity Service ...
|
||||
services.AddXIdentityService(
|
||||
lifeTime: lifeTime,
|
||||
configuration: Configuration
|
||||
);
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
//
|
||||
// Configure the HTTP request pipeline ...
|
||||
var isDevelopmentEnvironment = env.IsDevelopment();
|
||||
if (isDevelopmentEnvironment)
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
//
|
||||
// Force Https Redirection ...
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
//
|
||||
// Use Swagger Middleware (Only in Development) ...
|
||||
if (isDevelopmentEnvironment)
|
||||
{
|
||||
app.UseXSwagger();
|
||||
}
|
||||
|
||||
//
|
||||
// Using Cors (before Proxy so Browser Requests get CORS Headers) ...
|
||||
app.UseXCors();
|
||||
|
||||
//
|
||||
// Using Routing ...
|
||||
app.UseRouting();
|
||||
|
||||
//
|
||||
// Use xIdentityService (Authentication) ...
|
||||
app.UseXIdentityService();
|
||||
|
||||
//
|
||||
// Use Authorization ...
|
||||
app.UseAuthorization();
|
||||
|
||||
//
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\Controllers\StartupController.cs
|
||||
|
||||
using xCommons.Providers;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Controllers;
|
||||
using xExceptions.Constants;
|
||||
using xCommons.Configurations;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace xAiApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Runing when application start ...
|
||||
/// </summary>
|
||||
[Route("")]
|
||||
[AllowAnonymous]
|
||||
public class StartupController : XBaseController
|
||||
{
|
||||
|
||||
public StartupController(
|
||||
ILogger<StartupController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Show Configured Welcome Message
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("")]
|
||||
[AllowAnonymous]
|
||||
public virtual ActionResult<string> Index()
|
||||
{
|
||||
//
|
||||
var controllerName = GetControllerName();
|
||||
var message = $"{AppConfiguration.WelcomeMessage}";
|
||||
|
||||
//
|
||||
return Ok(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Global Exception Handler Endpoint (Production) ...
|
||||
/// Returns a Generic Error without Leaking Exception Details ...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[Route("error")]
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public virtual ActionResult Error()
|
||||
{
|
||||
//
|
||||
var error = XException.ActionFailed.ToXError();
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
### FILE: C:\Users\hkhazaeeasl\Documents\Projets\XProjects\xSaherelmWorkspace\xAiMcpServer\DI\DiExtensions.cs
|
||||
|
||||
using xIdentityHelper;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Authorization;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace xAiMcpServer.DI
|
||||
{
|
||||
public static class DiExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Register Authorization Policies
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="policies"></param>
|
||||
public static void AddXAuthorization(
|
||||
this IServiceCollection services,
|
||||
IDictionary<string, AuthorizationPolicy> policies = null
|
||||
)
|
||||
{
|
||||
//
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
//
|
||||
if (!policies.IsNull())
|
||||
{
|
||||
//
|
||||
// Fill Policies ...
|
||||
using (var policiesEnumerator = policies.GetEnumerator())
|
||||
{
|
||||
while (policiesEnumerator.MoveNext())
|
||||
{
|
||||
var policyDescriptor = policiesEnumerator.Current;
|
||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
var xPolicies = XAuthorizationHelper.GetXAuthorizationPolicies();
|
||||
if (!xPolicies.IsNull())
|
||||
{
|
||||
//
|
||||
// Fill Policies ...
|
||||
using (var policiesEnumerator = xPolicies.GetEnumerator())
|
||||
{
|
||||
while (policiesEnumerator.MoveNext())
|
||||
{
|
||||
var policyDescriptor = policiesEnumerator.Current;
|
||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
services.AddSingleton<IAuthorizationHandler, RequiredRolesHandler>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use Forward Headers Options for resolving behind a proxy issues ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static void UseXForwardOptions(this IApplicationBuilder source)
|
||||
{
|
||||
//
|
||||
var forwardOptions = new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
|
||||
RequireHeaderSymmetry = false
|
||||
};
|
||||
|
||||
//
|
||||
forwardOptions.KnownNetworks.Clear();
|
||||
forwardOptions.KnownProxies.Clear();
|
||||
|
||||
//
|
||||
// ref: https://github.com/aspnet/Docs/issues/2384
|
||||
source.UseForwardedHeaders(forwardOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1616
-347
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
.\ContextGenerator.ps1 .\xAiApi; .\ContextGenerator.ps1 .\Modules\xAiModels; .\ContextGenerator.ps1 .\Modules\xAiService
|
||||
.\ContextGenerator.ps1 .\xAiApi; .\ContextGenerator.ps1 .\xAiMcpServer; .\ContextGenerator.ps1 .\Modules\xAiModels; .\ContextGenerator.ps1 .\Modules\xAiService
|
||||
+1
-1
Submodule Modules/xAiModels updated: 9668f26ffe...25534f0273
+1
-1
Submodule Modules/xAiService updated: 44e764f0ff...2b99958f4c
+1
-1
Submodule Modules/xIdentityService updated: ac5517358e...6888c73fb8
Submodule
+1
Submodule xAiMcpServer added at 37cba11e5d
@@ -55,6 +55,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xApi", "xApi\xApi.csproj",
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xContentService", "Modules\xContentService\xContentService.csproj", "{BEFA4CA9-70B0-476D-95A3-E4D066AD48FE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xAiMcpServer", "xAiMcpServer\xAiMcpServer.csproj", "{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -365,6 +367,18 @@ Global
|
||||
{BEFA4CA9-70B0-476D-95A3-E4D066AD48FE}.Release|x64.Build.0 = Release|Any CPU
|
||||
{BEFA4CA9-70B0-476D-95A3-E4D066AD48FE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{BEFA4CA9-70B0-476D-95A3-E4D066AD48FE}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E31E920F-872A-4969-B6B0-4F5D3B27B5E5}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user