Skip to main content
Glama
crzyc0d3r

mcp-context-engineering

by crzyc0d3r

mcp-context-engineering

MCP 서버를 위한 컨텍스트 엔지니어링을 보여주는 작고 실행 가능한 프로젝트입니다. Model Context Protocol 서버가 모델의 컨텍스트 창에서 차지하는 공간을 작게 유지하여 에이전트의 비용을 줄이고 정확도를 높이는 방법을 다룹니다.

문제

MCP 클라이언트(Claude Desktop, Cursor, SDK 앱 등)가 MCP 서버에 연결하면 모든 광고된 도구 정의(이름, 설명, 전체 입력 스키마)를 모델의 컨텍스트로 가져옵니다. 도구가 30~60개 이상인 서버는 에이전트가 아무 작업도 하기 전에 정의만으로 10,000토큰을 훌쩍 넘게 소모할 수 있습니다. 이로 인해 두 가지 문제가 발생합니다.

  • 토큰 낭비. 에이전트가 절대 호출하지 않을 도구 정의에 비용을 지불하게 됩니다.

  • 정확도 저하. 모델이 관련 없는 도구에 주의가 분산되어 잘못된 도구를 선택하거나 매개변수를 환각할 가능성이 높아집니다.

두 가지 기법

이 프로젝트는 논리적 그룹으로 구성된 33개의 목업 "웹 데이터" 도구(Amazon, LinkedIn, TikTok, GitHub, Zillow, 브라우저 자동화, 배치 스크래핑 등) 카탈로그에 대해 이 수정 사항의 양면을 구현합니다.

  1. 광고할 도구의 범위를 지정하세요. 에이전트가 필요로 하는 기능만 로드합니다. 전체 그룹(GROUPS=social) 또는 개별 도구를 직접 선택(TOOLS=web_data_amazon_product,...)하여 로드할 수 있습니다. 선택한 정의만 컨텍스트에 도달합니다.

  2. 도구가 반환하는 출력을 최적화하세요. 스크래핑된 페이지가 컨텍스트에 들어가기 전에 토큰을 낭비하는 Markdown(굵게/기울임꼴, 이미지 구문, 제목 표시자, 코드 펜스, 링크 URL)을 제거하여 모델이 실제로 읽는 모든 단어를 유지합니다.

측정된 효과(번들된 오프라인 보고서 기준)

전체 카탈로그 = 33개 도구 ≈ 범위를 지정하지 않고 로드할 경우 정의 4,556토큰

구성

도구 수

정의 토큰

전체 대비 절약

기본(기본 도구만)

3

506

89%

GROUPS=ecommerce

9

1,318

71%

GROUPS=social

11

1,566

66%

GROUPS=social,business

14

1,973

57%

TOOLS= amazon,ebay,google_shopping

3

416

91%

GROUPS=research + 사용자 지정 도구 1개

6

917

80%

PRO_MODE=true(모두 로드)

33

4,556

0%

스크래핑된 페이지의 Markdown 제거: 243 → 149토큰(약 39% 감소).

숫자는 내장된 휴리스틱 토큰 추정기를 사용합니다. tiktoken이 설치된 경우 보고서에 --tiktoken을 전달하여 정확한 개수를 얻을 수 있습니다. 중요한 것은 비율이며, 이는 안정적입니다.

한 문장으로 요약

로드하는 도구의 범위를 지정하고, 반환되는 출력을 다듬고, 나머지 어려운 부분은 MCP 서버가 처리하도록 하세요.

코드 맵

mcp-context-engineering/
├── src/mcp_context_engineering/
│   ├── __init__.py          # Public API re-exports + version.
│   ├── tool_groups.py       # Source of truth for groups: BASE_TOOLS + 8 logical
│   │                        #   groups (ecommerce, social, business, research,
│   │                        #   finance, app_stores, browser, advanced_scraping)
│   │                        #   and helpers (all_tool_names, total_tool_count).
│   ├── tool_catalog.py      # Full catalog of 33 ToolSpecs: name, description,
│   │                        #   JSON input schema, and an OFFLINE mock handler
│   │                        #   each. Also MARKDOWN_TOOLS (which outputs to strip)
│   │                        #   and a SAMPLE_MARKDOWN_PAGE for the demo.
│   ├── context_config.py    # The scoping brain. Reads PRO_MODE / GROUPS / TOOLS,
│   │                        #   resolves the exact tool set (resolve_context),
│   │                        #   and defines named PRESETS.
│   ├── strip_markdown.py    # Dependency-free output optimiser: strips Markdown
│   │                        #   formatting, keeps words + code, links optional.
│   ├── token_utils.py       # Lightweight offline token estimator + tool-def
│   │                        #   token counting (tiktoken optional).
│   └── server.py            # The MCP server (official SDK low-level Server,
│   │                        #   stdio). Advertises only scoped tools; strips
│   │                        #   Markdown output. build_server() for tests.
├── scripts/
│   ├── run_server.py        # Launch the server over stdio (what a client runs).
│   └── token_report.py      # Offline demo: prints the savings tables above.
├── examples/
│   ├── claude_desktop_social_agent.json   # config: one group
│   ├── claude_desktop_price_monitor.json  # config: hand-picked tools
│   └── claude_desktop_pro_mode.json       # config: everything (baseline)
├── tests/
│   └── test_context_engineering.py        # 23 offline tests (unittest)
├── requirements.txt         # Just the official `mcp` SDK (tiktoken optional).
├── .env.example             # All config vars, documented.
└── .gitignore

구성 요소 간의 관계

tool_groups.py는 어떤 도구 이름이 어떤 그룹에 속하는지 정의합니다. tool_catalog.py는 각 이름에 전체 정의(설명 + 스키마)와 목업 핸들러를 제공합니다. context_config.py는 환경을 읽고 노출할 이름의 정확한 하위 집합을 결정합니다. server.pycontext_config에 해당 하위 집합을 요청하고 tools/list를 통해 해당 정의만 광고하며, MARKDOWN_TOOLS 도구가 호출되면 출력을 반환하기 전에 strip_markdown.py를 통해 실행합니다. token_utils.py는 네트워크에 연결하지 않고 두 가지 이점을 모두 정량화하는 오프라인 token_report.py를 지원합니다.

데이터 흐름

flowchart TD
    subgraph Config["Configuration (env vars)"]
        E["PRO_MODE / GROUPS / TOOLS<br/>STRIP_MARKDOWN"]
    end

    E --> RC["context_config.resolve_context()"]
    TG["tool_groups.py<br/>(group -> tool names)"] --> RC
    RC -->|"scoped list of tool names"| SRV["server.py (MCP Server)"]
    TC["tool_catalog.py<br/>(name -> description, schema, handler)"] --> SRV

    subgraph MCP["MCP session (stdio)"]
        CLIENT["MCP client / LLM agent"]
        SRV
    end

    SRV -->|"tools/list: ONLY scoped definitions"| CLIENT
    CLIENT -->|"tools/call(name, args)"| SRV
    SRV -->|"handler() output"| STRIP["strip_markdown.py<br/>(markdown tools only)"]
    STRIP -->|"trimmed text"| CLIENT

    RC -.offline.-> REPORT["scripts/token_report.py"]
    TC -.offline.-> REPORT
    TU["token_utils.py"] -.-> REPORT
    REPORT -.-> OUT["savings tables"]

빠른 시작

# 1. (optional) create a virtualenv
python -m venv .venv && source .venv/bin/activate    # Windows: .venv\Scripts\activate

# 2. install the one dependency
pip install -r requirements.txt

# 3. see the token savings - fully offline, no key, no network
python scripts/token_report.py
python scripts/token_report.py --json      # machine-readable

# 4. run the tests
python -m unittest discover -s tests -v

MCP 서버 실행

서버는 stdio를 통해 MCP를 사용하며 환경 변수로 완전히 구성됩니다.

# default: just the small base tool set
python scripts/run_server.py

# a focused social-media agent
GROUPS=social python scripts/run_server.py

# hand-pick exactly the tools a price monitor needs
TOOLS=web_data_amazon_product,web_data_ebay_product,web_data_google_shopping \
    python scripts/run_server.py

# the un-scoped baseline (loads everything)
PRO_MODE=true python scripts/run_server.py

# disable output trimming
STRIP_MARKDOWN=false GROUPS=social python scripts/run_server.py

유효한 그룹 ID: ecommerce, social, business, research, finance, app_stores, browser, advanced_scraping. 전체 변수 목록은 .env.example을 참조하세요.

MCP 클라이언트에 연결

examples/에 있는 파일 중 하나를 클라이언트의 서버 구성(Claude Desktop의 경우 claude_desktop_config.json)에 복사하고 /ABSOLUTE/PATH를 체크아웃 경로로 바꾼 다음 클라이언트를 다시 시작하세요. 세 가지 예제는 범위가 지정된 그룹, 직접 선택한 집합, 모두 로드하는 기준을 보여줍니다.

도구에 대한 참고 사항

이 프로젝트의 모든 도구 핸들러는 준비된 오프라인 샘플 데이터를 반환합니다. API 키도 네트워크 액세스도 없습니다. 목표는 라이브 사이트를 스크래핑하는 것이 아니라 컨텍스트 엔지니어링 패턴을 보여주는 것입니다. 실제로 사용하려면 tool_catalog.py의 핸들러를 실제 웹 데이터 백엔드 호출로 바꾸고 환경 변수에서 자격 증명을 읽도록 하세요(자리 표시자 WEB_DATA_API_KEY.env.example에 문서화되어 있음).

빌드 및 참고 자료

라이선스

MIT(LICENSE가 있으면 참조하고, 그렇지 않으면 샘플 코드를 MIT 라이선스로 간주)

-
license - not tested
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

  • Free public MCP for AI agents — 193 tools, 44 workflows. No API key.

  • Deterministic AI agent microtools, no accounts/API keys. fetch_extract: 98% token cut. 38 tools.

  • See, price, and control every tool call your AI agents make: policy checks, cost, and audit tools.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/crzyc0d3r/mcp-context-engineering'

If you have feedback or need assistance with the MCP directory API, please join our Discord server