Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
dist
.git
.github
.env
.env.*
coverage
*.log
tests
python_tests
10 changes: 9 additions & 1 deletion Connectors/Claude/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# AIFIAR for Claude
Local MCP profile for Claude Desktop. Build with `npm install` and `npm run build`; merge `mcp-config.json` into Claude Desktop's `claude_desktop_config.json`; replace the example absolute path; restart Claude Desktop and verify the tools. Claude web custom connectors require remote hosting. This profile is read-only.

Two connection modes are available:

- **Claude Desktop local:** merge `mcp-config.json` into Claude Desktop's `claude_desktop_config.json`, replace the example absolute path, rebuild AIFIAR, and restart Claude Desktop.
- **Remote MCP:** deploy the remote service using [the deployment guide](../../docs/remote-connector-deployment.md), configure an external OAuth/OIDC provider with the selected Claude client's exact redirect URI, then register the HTTPS endpoint `https://YOUR-HOST/mcp`.

For remote OAuth, the identity provider must issue RS256 JWT access tokens with `aifiar:read`, `aifiar_profile=claude`, and an explicit `aifiar_tools` array. The protected-resource metadata endpoint is `https://YOUR-HOST/.well-known/oauth-protected-resource/mcp`. Static bearer authentication is an alternative only when the selected Claude client supports custom bearer headers.

AIFIAR does not host the OAuth authorization server. The connector is read-only and does not bypass Claude's workspace or tool permissions.
13 changes: 12 additions & 1 deletion Connectors/GPT/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# AIFIAR for ChatGPT
Tool profile defined; ChatGPT web custom MCP apps require a reachable HTTPS endpoint and supported authentication. This repository does not ship that remote endpoint or OAuth server. A local stdio process is not a ChatGPT web connector. Do not deploy an unauthenticated relay. Use Codex profile for local Codex clients.

AIFIAR now has a remote stateless MCP endpoint suitable for ChatGPT custom MCP connectors when the connector setup supports OAuth.

1. Deploy the remote service using [the deployment guide](../../docs/remote-connector-deployment.md).
2. Configure an external OAuth/OIDC identity provider with ChatGPT's exact redirect URI and the AIFIAR audience.
3. Configure the access token claims: `scope` includes `aifiar:read`, `aifiar_profile` is `gpt`, and `aifiar_tools` is the explicit allowed tool array.
4. Register the deployed HTTPS endpoint `https://YOUR-HOST/mcp` as the MCP server.
5. Complete the OAuth connection in the ChatGPT connector setup and verify the available tools.

The protected-resource metadata endpoint is `https://YOUR-HOST/.well-known/oauth-protected-resource/mcp`. AIFIAR validates the external provider's RS256 access tokens through the configured JWKS URL. AIFIAR does not host the identity provider or manage user login/consent.

Static bearer/API-key mode is available only if the selected ChatGPT connector setup UI offers that authentication method. Do not bypass an OAuth requirement by enabling unauthenticated access. The remote tool profile is read-only and exposes only explicitly granted tools.
25 changes: 24 additions & 1 deletion Connectors/GPT/profile.json
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
{"id":"gpt","protocol":"MCP","transport":"remote-streamable-http-required","authentication":"host-managed-authentication-required","status":"requires-remote-host","tools":["aifiar_status","aifiar_list_models","aifiar_get_instructions","aifiar_prepare_repository"],"limitations":["Local stdio is not a ChatGPT web connector.","No public HTTP endpoint or OAuth server is shipped.","Remote deployment must enforce authenticated per-user authorization."]}
{
"id": "gpt",
"protocol": "MCP Streamable HTTP",
"transport": "stateless-remote-http",
"endpoint": "https://YOUR-HOST/mcp",
"authentication": [
"external-oauth-oidc-rs256",
"static-bearer-if-host-supports-api-key"
],
"protectedResourceMetadata": "https://YOUR-HOST/.well-known/oauth-protected-resource/mcp",
"oauthResourceServer": true,
"authorizationServer": "external-identity-provider",
"profileClaim": "aifiar_profile",
"profileValue": "gpt",
"requiredScope": "aifiar:read",
"toolAllowlistClaim": "aifiar_tools",
"status": "ready-for-deployment",
"limitations": [
"Requires operator-provided HTTPS hosting and external OAuth/OIDC identity provider.",
"No built-in OAuth authorization server, login UI, or user database.",
"Stateless transport does not provide SSE GET or resumable sessions.",
"Read-only tools only."
]
}
5 changes: 4 additions & 1 deletion Connectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ Read-only MCP tools: `aifiar_status`, `aifiar_list_models`, `aifiar_get_instruct

Requires Node.js 20+. Run `npm install`, `npm run build`, then `npm run connector:claude`, `connector:gpt`, `connector:grok`, `connector:codex`, or `connector:cursor`. MCP stdio reserves stdout for JSON-RPC.

Claude Desktop, Codex CLI, and Cursor use local stdio profiles. ChatGPT web requires remote HTTPS hosting and host-approved authentication. Grok is compatibility-unverified until native client support is confirmed. Never expose stdio directly to the internet.
Claude Desktop, Codex CLI, and Cursor use local stdio profiles. ChatGPT web requires remote HTTPS hosting and host-approved authentication. Grok is compatibility-unverified until native client support is confirmed. Never expose stdio directly to the internet.

## Remote hosting
Remote MCP deployment and external OAuth/OIDC setup are documented in [Remote connector deployment](../docs/remote-connector-deployment.md). ChatGPT and remote Claude profiles can use OAuth/OIDC access tokens; static bearer tokens are available for compatible clients. AIFIAR is a resource server, not an identity provider.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:22-alpine AS build
WORKDIR /app
COPY package.json tsconfig.json ./
COPY core ./core
COPY models ./models
COPY connectors ./connectors
COPY Main.md AGENTS.md ./
RUN npm install --ignore-scripts && npm run build

FROM node:22-alpine AS runtime
ENV NODE_ENV=production AIFIAR_REMOTE_HOST=0.0.0.0 AIFIAR_REMOTE_PORT=8787
WORKDIR /app
COPY --from=build --chown=node:node /app/dist ./dist
COPY --from=build --chown=node:node /app/models ./models
COPY --from=build --chown=node:node /app/Main.md /app/AGENTS.md ./
USER node
EXPOSE 8787
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s CMD node -e "fetch('http://127.0.0.1:8787/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
CMD ["node","dist/connectors/remote/httpServer.js"]
2 changes: 2 additions & 0 deletions Main.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
| `models/<provider>/` | Provider integration instructions | Only when working with that provider or explicitly applying its guidance |
| `Connectors/<Host>/` | Host-specific MCP connector setup | Integrating Claude, ChatGPT, Grok, Codex, or Cursor |
| `connectors/shared/` | Shared MCP server and tool handlers | Changing connector protocol or tool behavior |
| `connectors/remote/` | Authenticated stateless Streamable HTTP MCP service | Remote connector hosting and authentication |
| `Connectors/` | Host-specific connector configuration and setup | Installing AIFIAR in supported AI clients |
| `models/gpt/` | GPT family profiles and shared GPT workflow | Only when the active model family is confirmed to be GPT |
| `models/PROVIDER_TEMPLATE.md` | Template for adding a provider | Creating a new provider integration |
| `core/modelExecutionInstructions.ts` | Task-kind, provider, and language-aware quality guidance for text adapters | Changing prompt construction or model output workflow |
Expand Down
9 changes: 9 additions & 0 deletions connectors/remote/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import{createHash,timingSafeEqual}from"node:crypto";
export interface RemotePrincipal{subject:string;profile:"claude"|"gpt"|"grok"|"codex"|"cursor";tools:readonly string[];requestsPerMinute:number}
interface TokenRecord extends RemotePrincipal{digest:Buffer}
const PROFILE_TOOLS=["aifiar_status","aifiar_list_models","aifiar_get_instructions","aifiar_prepare_repository"];
function isRecord(v:unknown):v is Record<string,unknown>{return v!==null&&typeof v==="object"&&!Array.isArray(v)}
export function loadRemoteTokens(raw=process.env.AIFIAR_REMOTE_TOKENS,allowEmpty=false):TokenRecord[]{if(!raw){if(allowEmpty)return[];throw new Error("AIFIAR_REMOTE_TOKENS is required for remote connector mode.");}let parsed:unknown;try{parsed=JSON.parse(raw)}catch{throw new Error("AIFIAR_REMOTE_TOKENS must be valid JSON.")}if(!Array.isArray(parsed)||parsed.length<1||parsed.length>1000)throw new Error("AIFIAR_REMOTE_TOKENS must contain 1 to 1000 entries.");const seen=new Set<string>(),seenDigests=new Set<string>();return parsed.map((v,i)=>{if(!isRecord(v)||typeof v.token!=="string"||v.token.length<32||v.token.length>512||typeof v.subject!=="string"||!/^[A-Za-z0-9._:@-]{1,128}$/.test(v.subject)||!["claude","gpt","grok","codex","cursor"].includes(String(v.profile))||!Array.isArray(v.tools)||!v.tools.every(t=>typeof t==="string"&&PROFILE_TOOLS.includes(t))||new Set(v.tools).size!==v.tools.length)throw new Error("Invalid remote token entry at index "+i+".");const subject=v.subject as string,digest=createHash("sha256").update(v.token,"utf8").digest(),digestHex=digest.toString("hex");if(seenDigests.has(digestHex))throw new Error("Remote tokens must be unique.");seenDigests.add(digestHex);if(seen.has(subject))throw new Error("Remote token subjects must be unique.");seen.add(subject);const rpm=v.requestsPerMinute??60;if(!Number.isInteger(rpm)||Number(rpm)<1||Number(rpm)>600)throw new Error("requestsPerMinute must be an integer from 1 to 600.");return{subject,profile:v.profile as RemotePrincipal["profile"],tools:[...v.tools] as string[],requestsPerMinute:Number(rpm),digest}})}
export function authenticateBearer(header:string|undefined,records:readonly TokenRecord[]):RemotePrincipal|null{if(!header||!/^Bearer [A-Za-z0-9._~+/-]+=*$/i.test(header))return null;const token=header.slice(7);if(token.length<32||token.length>512)return null;const digest=createHash("sha256").update(token,"utf8").digest();let match:TokenRecord|undefined;for(const record of records){const equal=timingSafeEqual(digest,record.digest);if(equal)match=record;}return match?{subject:match.subject,profile:match.profile,tools:match.tools,requestsPerMinute:match.requestsPerMinute}:null}
export function principalFromEnv(raw=process.env.AIFIAR_REMOTE_TOKENS):readonly RemotePrincipal[]{return loadRemoteTokens(raw).map(({subject,profile,tools,requestsPerMinute})=>({subject,profile,tools,requestsPerMinute}))}
export async function authenticateRemoteBearer(header:string|undefined,records:readonly TokenRecord[],oidc?:((header:string|undefined)=>Promise<RemotePrincipal|null>)):Promise<RemotePrincipal|null>{const local=authenticateBearer(header,records);if(local)return local;return oidc?oidc(header):null}
3 changes: 3 additions & 0 deletions connectors/remote/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface RemoteConfig{host:string;port:number;path:string;publicUrl:URL;allowedHosts:Set<string>;allowedOrigins:Set<string>;maxBodyBytes:number;maxRequestsPerMinute:number;trustProxy:boolean}
const csv=(v:string|undefined)=>new Set((v??"").split(",").map(x=>x.trim().toLowerCase()).filter(Boolean));
export function loadRemoteConfig(env=process.env):RemoteConfig{const raw=env.AIFIAR_REMOTE_PUBLIC_URL;if(!raw)throw new Error("AIFIAR_REMOTE_PUBLIC_URL is required.");let publicUrl:URL;try{publicUrl=new URL(raw)}catch{throw new Error("AIFIAR_REMOTE_PUBLIC_URL must be an absolute URL.")}if(publicUrl.protocol!=="https:"||publicUrl.username||publicUrl.password||publicUrl.search||publicUrl.hash)throw new Error("AIFIAR_REMOTE_PUBLIC_URL must be HTTPS and contain no credentials, query, or fragment.");const path=env.AIFIAR_REMOTE_PATH??"/mcp";if(!path.startsWith("/")||path.includes("?")||path.includes("#")||path.includes(".."))throw new Error("AIFIAR_REMOTE_PATH must be a safe absolute path.");if(publicUrl.pathname.replace(/\/$/,"")!==path.replace(/\/$/,""))throw new Error("Public URL path must exactly match AIFIAR_REMOTE_PATH.");const allowedHosts=csv(env.AIFIAR_REMOTE_ALLOWED_HOSTS);allowedHosts.add(publicUrl.host.toLowerCase());const allowedOrigins=csv(env.AIFIAR_REMOTE_ALLOWED_ORIGINS);const port=Number(env.AIFIAR_REMOTE_PORT??8787),maxBodyBytes=Number(env.AIFIAR_REMOTE_MAX_BODY_BYTES??1048576),maxRequestsPerMinute=Number(env.AIFIAR_REMOTE_MAX_REQUESTS_PER_MINUTE??120);if(!Number.isInteger(port)||port<1||port>65535)throw new Error("Remote port must be an integer from 1 to 65535.");if(!Number.isInteger(maxBodyBytes)||maxBodyBytes<1024||maxBodyBytes>10485760)throw new Error("Remote body limit must be 1 KiB to 10 MiB.");if(!Number.isInteger(maxRequestsPerMinute)||maxRequestsPerMinute<1||maxRequestsPerMinute>10000)throw new Error("Remote global rate limit must be 1 to 10000 requests per minute.");return{host:env.AIFIAR_REMOTE_HOST??"127.0.0.1",port,path,publicUrl,allowedHosts,allowedOrigins,maxBodyBytes,maxRequestsPerMinute,trustProxy:false}}
Loading
Loading