plan for mcp server
This commit is contained in:
1 parent
843aa187ad
commit
26a4bdc7d1
6 files changed
+311
No files matched your search
@@ -0,0 +1,25 @@
|
||||
# ContextForge adapter
|
||||
|
||||
This directory exposes the static blog as three read-only REST tools that ContextForge can publish through MCP:
|
||||
|
||||
- `bis_blog_site_info`: site metadata and feed URLs.
|
||||
- `bis_blog_list_posts`: the public post index with exact slugs.
|
||||
- `bis_blog_read_post`: one post in Markdown by slug.
|
||||
|
||||
The Astro build generates the upstream JSON endpoints. Deploy the site before registering or updating the tools.
|
||||
|
||||
## Register
|
||||
|
||||
Use a short-lived ContextForge token with permission to list, create, and update tools. Keep it in the current process only:
|
||||
|
||||
```powershell
|
||||
$env:CONTEXTFORGE_URL = 'https://contextforge.example.com'
|
||||
$env:CONTEXTFORGE_TOKEN = '<short-lived-token>'
|
||||
pwsh -NoLogo -NoProfile -File .\contextforge\Register-BlogTools.ps1
|
||||
```
|
||||
|
||||
The script prefers the canonical `/v1` API and falls back to the legacy unversioned API when the server returns `404`. Existing tools with the same names are updated; missing tools are created. Use `-WhatIf` to inspect the planned changes without writing to ContextForge.
|
||||
|
||||
After registration, add the three tools to a ContextForge virtual server in the Admin UI. That server's SSE or Streamable HTTP endpoint is the MCP endpoint consumed by clients. Keeping virtual-server membership as an explicit admin action avoids silently changing an existing server's authorization boundary.
|
||||
|
||||
The checked-in manifest contains no ContextForge credentials. Its upstream allowlist is restricted to `blog.biss.click`, and the tools are read-only `GET` requests.
|
||||
@@ -0,0 +1,132 @@
|
||||
[CmdletBinding(SupportsShouldProcess)]
|
||||
param(
|
||||
[Parameter()]
|
||||
[string]$BaseUrl = $env:CONTEXTFORGE_URL,
|
||||
|
||||
[Parameter()]
|
||||
[string]$Token = $env:CONTEXTFORGE_TOKEN,
|
||||
|
||||
[Parameter()]
|
||||
[string]$ManifestPath = (Join-Path $PSScriptRoot 'blog-tools.json')
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($BaseUrl)) {
|
||||
throw 'Set CONTEXTFORGE_URL or pass -BaseUrl (for example, https://contextforge.example.com).'
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Token)) {
|
||||
throw 'Set CONTEXTFORGE_TOKEN or pass -Token. The token is never written to disk.'
|
||||
}
|
||||
|
||||
$gatewayUri = $null
|
||||
if (-not [Uri]::TryCreate($BaseUrl, [UriKind]::Absolute, [ref]$gatewayUri)) {
|
||||
throw "BaseUrl is not an absolute URL: $BaseUrl"
|
||||
}
|
||||
|
||||
$isLoopback = $gatewayUri.IsLoopback
|
||||
if ($gatewayUri.Scheme -ne 'https' -and -not $isLoopback) {
|
||||
throw 'ContextForge must use HTTPS unless it is running on a loopback address.'
|
||||
}
|
||||
|
||||
$resolvedManifest = (Resolve-Path -LiteralPath $ManifestPath).Path
|
||||
$tools = @(Get-Content -LiteralPath $resolvedManifest -Raw -Encoding UTF8 | ConvertFrom-Json)
|
||||
if ($tools.Count -eq 0) {
|
||||
throw "No tools were found in $resolvedManifest"
|
||||
}
|
||||
|
||||
$headers = @{
|
||||
Authorization = "Bearer $Token"
|
||||
Accept = 'application/json'
|
||||
}
|
||||
$root = $BaseUrl.TrimEnd('/')
|
||||
|
||||
function Invoke-ContextForgeRequest {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateSet('GET', 'POST', 'PUT')]
|
||||
[string]$Method,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Path,
|
||||
|
||||
[Parameter()]
|
||||
[object]$Body
|
||||
)
|
||||
|
||||
$request = @{
|
||||
Uri = "$root$Path"
|
||||
Method = $Method
|
||||
Headers = $headers
|
||||
ErrorAction = 'Stop'
|
||||
}
|
||||
|
||||
if ($null -ne $Body) {
|
||||
$request.ContentType = 'application/json; charset=utf-8'
|
||||
$request.Body = $Body | ConvertTo-Json -Depth 30
|
||||
}
|
||||
|
||||
Invoke-RestMethod @request
|
||||
}
|
||||
|
||||
function Get-EntityArray {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[object]$Response,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$Property
|
||||
)
|
||||
|
||||
if ($Response -is [Array]) {
|
||||
return @($Response)
|
||||
}
|
||||
|
||||
if ($Response.PSObject.Properties.Name -contains $Property) {
|
||||
return @($Response.$Property)
|
||||
}
|
||||
|
||||
return @()
|
||||
}
|
||||
|
||||
$apiPrefix = '/v1'
|
||||
try {
|
||||
$health = Invoke-RestMethod -Uri "$root/health" -Method Get -ErrorAction Stop
|
||||
Write-Verbose ("ContextForge health: {0}" -f ($health | ConvertTo-Json -Compress -Depth 5))
|
||||
$toolResponse = Invoke-ContextForgeRequest -Method GET -Path '/v1/tools?limit=0&include_pagination=false'
|
||||
}
|
||||
catch {
|
||||
$statusCode = if ($null -ne $_.Exception.Response) {
|
||||
[int]$_.Exception.Response.StatusCode
|
||||
}
|
||||
else {
|
||||
0
|
||||
}
|
||||
|
||||
if ($statusCode -ne 404) {
|
||||
throw
|
||||
}
|
||||
|
||||
$apiPrefix = ''
|
||||
$toolResponse = Invoke-ContextForgeRequest -Method GET -Path '/tools?limit=0&include_pagination=false'
|
||||
}
|
||||
|
||||
$existingTools = Get-EntityArray -Response $toolResponse -Property 'tools'
|
||||
$results = foreach ($tool in $tools) {
|
||||
$existing = $existingTools | Where-Object { $_.name -eq $tool.name } | Select-Object -First 1
|
||||
|
||||
if ($null -ne $existing) {
|
||||
if ($PSCmdlet.ShouldProcess($tool.name, 'Update ContextForge REST tool')) {
|
||||
$updated = Invoke-ContextForgeRequest -Method PUT -Path "$apiPrefix/tools/$($existing.id)" -Body $tool
|
||||
[pscustomobject]@{ Name = $tool.name; Action = 'updated'; Id = $updated.id }
|
||||
}
|
||||
}
|
||||
elseif ($PSCmdlet.ShouldProcess($tool.name, 'Create ContextForge REST tool')) {
|
||||
$created = Invoke-ContextForgeRequest -Method POST -Path "$apiPrefix/tools" -Body @{ tool = $tool }
|
||||
[pscustomobject]@{ Name = $tool.name; Action = 'created'; Id = $created.id }
|
||||
}
|
||||
}
|
||||
|
||||
$results | Format-Table -AutoSize
|
||||
@@ -0,0 +1,75 @@
|
||||
[
|
||||
{
|
||||
"name": "bis_blog_site_info",
|
||||
"displayName": "Bi's Blog - Site Info",
|
||||
"description": "Read public metadata and feed URLs for Bi's Blog.",
|
||||
"url": "https://blog.biss.click/api/site.json",
|
||||
"integration_type": "REST",
|
||||
"request_type": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"timeout_ms": 10000,
|
||||
"expose_passthrough": false,
|
||||
"allowlist": [
|
||||
"blog.biss.click"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bis_blog_list_posts",
|
||||
"displayName": "Bi's Blog - List Posts",
|
||||
"description": "List all public blog posts with slugs, summaries, dates, tags, categories and canonical URLs. Use the returned slug with bis_blog_read_post to read one article.",
|
||||
"url": "https://blog.biss.click/api/posts.json",
|
||||
"integration_type": "REST",
|
||||
"request_type": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"timeout_ms": 15000,
|
||||
"expose_passthrough": false,
|
||||
"allowlist": [
|
||||
"blog.biss.click"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "bis_blog_read_post",
|
||||
"displayName": "Bi's Blog - Read Post",
|
||||
"description": "Read one public blog post as Markdown. Call bis_blog_list_posts first and pass an exact returned slug.",
|
||||
"url": "https://blog.biss.click/api/posts/{slug}.json",
|
||||
"integration_type": "REST",
|
||||
"request_type": "GET",
|
||||
"headers": {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"slug": {
|
||||
"type": "string",
|
||||
"description": "Exact article slug returned by bis_blog_list_posts.",
|
||||
"minLength": 1,
|
||||
"pattern": "^[A-Za-z0-9_-]+$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"slug"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"timeout_ms": 15000,
|
||||
"expose_passthrough": false,
|
||||
"allowlist": [
|
||||
"blog.biss.click"
|
||||
]
|
||||
}
|
||||
]
|
||||
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user