Developers API

Use SAHMK MCP with LM Studio and Local AI Models (Gemma + Qwen)

Set up SAHMK MCP with LM Studio for private/local Saudi market workflows. Practical setup, tested local models, a production-ready system prompt, context guidance, prompts, and best practices.

LM StudioMCPLocal ModelsIntermediate7 min read

Why this setup matters

  • Run private or local AI workflows without sending full conversation history to hosted assistants.
  • Keep Saudi market data structured and reliable through SAHMK MCP tools.
  • Useful for internal tooling, research workflows, and developer-side analysis loops.

What you need

  • LM Studio installed and running
  • SAHMK MCP installed
  • SAHMK API key
  • A local model loaded in LM Studio

Tested model examples

  • Gemma 4 26B E2B
  • Qwen 3.6 35B A3B

You can use other local models as long as tool calling is stable in your runtime.

LM Studio MCP setup (simple flow)

  1. Install SAHMK MCP:
bash
pip install -U sahmk-mcp
  1. Set your API key in the environment used by LM Studio:
bash
export SAHMK_API_KEY="shmk_live_your_key_here"
  1. Add a stdio MCP server entry in LM Studio (exact UI labels can vary by version):
json
{
  "name": "sahmk",
  "transport": "stdio",
  "command": "sahmk-mcp",
  "env": {
    "SAHMK_API_KEY": "shmk_live_your_key_here"
  }
}
  1. Select your local model, open a new chat, and verify MCP tools are available.

Recommended system prompt

Use this as your default system prompt for Saudi market analysis in LM Studio:

text
You are a Saudi market intelligence assistant.

Focus:

* Saudi stocks
* company snapshots
* dividends
* historical performance
* sectors
* market context
* recent news

Style:

* concise
* factual
* practical
* no fluff
* no dramatic metaphors
* explain clearly but briefly
* use tools often
* do not guess reasons for price moves unless supported by tool output or web results
* if uncertain, say so

Tools:

* Use Sahmk MCP for Saudi market data.
* Use Brave Search for fresh public news or external context.
* Prefer Sahmk MCP for prices, dividends, company data, historicals, and sectors.
* Prefer Brave Search only for recent developments, announcements, or public web context.

Language:

* Reply in the user’s language.
* Arabic should feel natural, clear, and investor-friendly.

Output:

* answer directly
* keep it compact by default
* expand only when the user asks for deeper analysis

Context length guidance

  • Default small contexts like 4K are often too limiting for multi-turn market workflows.
  • Use 64K context as a practical baseline if model/runtime/hardware support it.
  • 128K+ is better for longer research sessions, multi-step comparisons, and tool-heavy chats.

Actual usable context depends on model quality, runtime behavior, and available hardware.

Example prompts

text
Give me a full snapshot of Aramco: current price, dividend yield, recent performance, and latest important news.
قارن بين أرامكو والراجحي من ناحية الاستثمار الآن
Show Aramco’s price history for the last 3 months
Which Saudi sectors look strongest right now based on price action and recent developments?
اعطني ملخص عن سابك وتوزيعاتها وأداء السهم مؤخراً

Limitations and best practices

  • Use SAHMK MCP for structured Saudi market data.
  • Use web search only for fresh public context.
  • Keep answers concise by default.
  • Prefer models with stronger tool use and longer context windows.
  • If sector/news reasoning is unclear, state uncertainty instead of inventing causes.

Next steps