Skip to content

defineConfig

ガードレールの設定オブジェクトを作成します。3つの呼び出し方があります。

シグネチャ

ts
// ゼロコンフィグ (PII + シークレット保護がデフォルト)
const config = defineConfig();

// プリセット・ルール指定
const config = defineConfig(input);

// 既存の GuardrailsConfig をそのまま通す
const config = defineConfig(config);

パラメーター

引数なしの場合、PII + シークレット保護がデフォルトで有効になります。

ConfigInput を渡す場合:

パラメーターデフォルト説明
rules(Rule | RuleBuilder)[]--適用するルールの配列
protectstring[]--有効にするプリセット名
serversServerConfig[]--バックエンド MCP サーバーの定義
onViolation"block" | "warn" | "log""block"違反時のデフォルト動作
traceTraceConfig--トレース設定
logLogConfig--ログ設定

プリセット名

プリセット名内容
"pii"メール、電話番号、クレジットカード等の PII を検出・ブロック
"secrets"API キー、トークン、秘密鍵等を検出・ブロック
"prompt-injection"プロンプトインジェクション攻撃を検出・ブロック

戻り値

GuardrailsConfig — ビルダーとプリセットが解決済みの最終設定オブジェクト。

使用例

ゼロコンフィグ

ts
import { defineConfig } from "open-mcp-guardrails";

export default defineConfig();

プリセット指定

ts
import { defineConfig } from "open-mcp-guardrails";

export default defineConfig({
  protect: ["pii", "secrets", "prompt-injection"],
});

カスタムルール

ts
import { defineConfig, pii, secrets, flow, tool } from "open-mcp-guardrails";

export default defineConfig({
  rules: [
    pii().block(),
    secrets().exclude("generic_secret").warn(),
    flow("get_website").to("send_email").block(),
    tool("send_email")
      .check(args => !(args.to as string)?.endsWith("@company.com"))
      .block("Only @company.com addresses allowed"),
  ],
});

プリセット + カスタムルール

protectrules は併用可能です。protect のルールが先に適用されます:

ts
export default defineConfig({
  protect: ["pii"],
  rules: [
    secrets().exclude("generic_secret").block(),
    flow("get_website").to("send_email").block(),
  ],
});

関連